我们以前可以在搜索框中输入搜索字段、地址,然后按键盘上的 ENTER 键并获得搜索结果。
我做了几处更改,但无法确定导致 ENTER 键行为异常的更改。它不是提交,而是刷新页面。
我已尝试以下各项来停止页面刷新:
<form onSubmit="return false;">
<form onkeypress="return event.keyCode != 13">
每个作品。
但是,我不能再按 ENTER 键并显示结果。
我需要做什么来解决这个问题?
下面是js:
function getData()
{
dijit.byId("advanceSearchDialog").hide();
var form = document.getElementById("searchForm");
var form2 = document.getElementById("featuresForm")
var searchText = form.searchBox.value.replace(/-/g,"");
form.searchBox.value = searchText;
if (searchText != "")
{
// collect features to search for:
var features = [ ];
var featTypes = form2.featType;
for ( var f = 0; f < featTypes.length; ++f )
{
if ( featTypes[f].checked ) features.push( featTypes[f].value );
}
featureList = "'" + features.join("','") + "'";
searchMsg("Searching for '" + searchText + "' ...");
featureID = "";
var accord = dijit.byId("accordianContainer");
var resultsPane = dijit.byId("resultsPane");
accord.selectChild(resultsPane,true);
doGlobalSearch( searchText, featureList );
}
else
{
searchMsg("No search criteria entered, enter search text");
}
}
function searchKey(e){
// special case for IE to capture <enter> in the search box
var key = window.event ? e.keyCode : e.which;
var keychar = String.fromCharCode(key);
if (key == 13)
getData();
}
<form id="searchForm" class="search_field" method="get" action="">
<input name="searchBox" id="searchBox" value="" />
<button type="button" onclick="getData()"><img src="images/magnifying_glass.png" alt="Search" /></button>
</form>
谢谢