我想捕获回车键以触发按钮点击。
我有以下 JavaScript 代码:
带有 HTML
这段话的意思是“这个在IE浏览器上可以正常工作,但在Firefox上却不能,为什么?有人能修复这个javascript代码使其在所有浏览器上都能正常工作吗?谢谢。”
我有以下 JavaScript 代码:
function doClick(buttonName,e)
{
//the purpose of this function is to allow the enter key to
//point to the correct button to click.
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
{
//Get the button the user wants to have clicked
var btn = document.getElementById('submit');
if (btn != null)
{ //If we find the button click it
btn.click();
event.keyCode = 0
}
}
}
带有 HTML
<input type="button" id="submit" value="Search" onClick="doSomeThing();" />
<input type="text" name="search" onKeyPress="doClick('submit',event)" />
这段话的意思是“这个在IE浏览器上可以正常工作,但在Firefox上却不能,为什么?有人能修复这个javascript代码使其在所有浏览器上都能正常工作吗?谢谢。”