在我的純HTML頁面中,我有一個用戶輸入關鍵字,然後重定向到asp頁面的文本框。 當用戶點擊提交按鈕時,我使用javascript捕獲關鍵字。如何在html中捕獲輸入密鑰並重定向到asp頁面?
但是當用戶按回車時,HTML頁面將重新加載並返回錯誤頁面。 我如何捕捉輸入關鍵事件?這樣它會重定向到asp頁面。 感謝
我的javascript代碼如下:
function searching() {
var keywordsStr = document.getElementById('keywords').value;
var cmd = "http://xxx/SearchEngine/Searching.aspx?keywords=" + encodeURI(keywordsStr) ;
window.open(cmd);
}
我的HTML代碼如下:
<form name="form1" method="post" action="" >
<input name="keywords" type="text" id="keywords" size="50" >
<input type="submit" name="btn_search" id="btn_search" value="Search" onClick="javascript:searching(); return false;">
<input type="reset" name="btn_reset" id="btn_reset" value="Reset">
</form>
我創建[A JSFiddle.net(http://jsfiddle.net/bfuxx/)根據您的*精確*代碼,它的工作原理沒有問題(儘管由於替換域名,您將被重定向到pron站點)。你確定'searching()'可以作爲一個函數嗎?您是否嘗試過使用[Firebug for Firefox](http://getfirebug.com)或IE和Chrome中的開發人員工具(各自爲F5)? – freefaller