小编Swe*_*ell的帖子

捕获Enter键以使用javascript导致按钮单击

我想捕获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)

html javascript

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

html ×1

javascript ×1