您好,感谢您的帮助!
我目前正在使用SharePoint 2010.我有一个搜索框,它使用图像onclick()事件来触发搜索 . 单击图像图标时效果很好但在文本框中单击输入一次时根本不起作用 . 这是按钮的代码 .
<div style="position:relative; top:-3px; ">
<label for="Search"><b>SEARCH</b>
</label>
<label for="Content">
<input id="Content" type="radio" name="radiou" value="URL" checked="checked" style="margin-bottom:5px" />Content</label>
<label for="Employees">
<input id="Employee" type="radio" name="radiou" value="URL" style="margin-bottom:5px" />Employee</label>
<input id="search_txt" title="Enter search words" type="text" name="k" maxlength="80" size="25" />
<img src="/Style Library/Images/Search_button.png" onclick="submitSearch()" alt="Search Button" style="margin:0px; position:relative; top:7px; width:30px;"></img>
</div>
这是在按钮点击时激活代码的javascript . 我想在键入一个术语并单击Enter键后也会被解雇 .
< script type = "text/javascript"
language = "JavaScript" >
// <![CDATA[
function submitSearch() {
var radiovals = document.getElementsByName("radiou");
var hostnameforsearch = window.location.hostname;
if (radiovals[0].checked) {
queryVal = $('#search_txt').val();
var searchUrl = 'http://' + hostnameforsearch + '/search/results.aspx?k=' + queryVal + '&u=' + hostnameforsearch + '&cs=This Site';
window.location = searchUrl;
return false;
} else {
queryVal = $('#search_txt').val();
window.open('http://search.URL.com/Pages/PeopleResults.aspx?k=' + queryVal);
};
}; // ]]>
< /script>
感谢您的帮助!肯
4 回答
使用javascript检测按下的输入键然后提交
演示:https://jsfiddle.net/farhanbaloch/devevwwy/
使用
<form>
而不是<div>
并将事件处理程序附加到窗体上的submit
事件 .嗯,很简单,你没有在输入中提交submitSearch .
然后在你的代码中
这对我有用...
使用Javascript
缺少事件处理程序