jQuery: textbox keyup firing twice

前端 未结 8 1857
南笙
南笙 2021-01-11 16:09

I\'m having a textbox and assigned the following function (it\'s the only function assigned):

txt.bind(\"keyup\",function(event){
    if(event.keyCode==13)
          


        
相关标签:
8条回答
  • 2021-01-11 17:00

    I had a similar problem
    found that object with assigned keyup function was inside another object
    first was div second was input
    found that keyup was assigned to input and to a div with this input

    0 讨论(0)
  • 2021-01-11 17:02

    Here's my workaround for the same issue:

    $('input').live('keyup keydown', function(e) {
        var thisKey = e.keyCode ? e.keyCode : e.which;
        if (thisKey == 13) {
            e.preventDefault();
            e.stopPropagation();
            if (e.type == 'keyup') {
                $(this).closest('form').submit();   
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题