Prevent form submission on Enter key press

前端 未结 19 2200
失恋的感觉
失恋的感觉 2020-11-22 04:18

I have a form with two text boxes, one select drop down and one radio button. When the enter key is pressed, I want

19条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 05:07

    A much simpler and effective way from my perspective should be :

    function onPress_ENTER()
    {
            var keyPressed = event.keyCode || event.which;
    
            //if ENTER is pressed
            if(keyPressed==13)
            {
                alert('enter pressed');
                keyPressed=null;
            }
            else
            {
                return false;
            }
    }
    

提交回复
热议问题