开发者

Document Click triggered on 'enter' form submission

I'm having trouble understanding why a click event binded to the document would be triggered through an 'enter' form submission. Here's the test page I'm looking at:

<html>
<head>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js'></script>
    <script type='text/javascript'>
        $(function(){
            // Form Submission
            $('form').bind('submit', function(event){
                console.log('Submit: ', event);
                return false;
            });
            // Input events
            $('input[type=text]').bind('keyup', function(event){
                console.log('Keyup: ', event);
            }).bind('keydown', function(event){
                console.log('Keydown: ', e开发者_如何学编程vent)
            });
            // Doc Click
            $(document).click(function(event){
                console.log('Document Click: ', event);
            });
        });
    </script>
</head>
<body>
    <form action='test.html' method='GET'>
        <input type='text'>
        <input type='submit' value='Submit'>
    </form>
</body>
</html>

Any idea's?


Change type='submit' to type='button'. Tested on IE8 and FF3.5.


The form will submit when you only have 1 field and you hit enter. If you put more than one input field on it it will not do this. This is a browser dependent behavior.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜