我想捕获Enter键以使按钮单击
我有这个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
}
}
}
Run Code Online (Sandbox Code Playgroud)
用html
<input type="button" id="submit" value="Search" onClick="doSomeThing();" /> …Run Code Online (Sandbox Code Playgroud)