2013-10-30 146 views
0

由于某种原因,我的代码仅在第二次点击输入时才有效,是否有办法让它第一次加载?jQuery onBlur只能在第二次点击时工作

function postTitleCheck() { 
    $('.postForm').on('blur', '#post_title', function (e) { 
     alert('hi'); 
     $(".postForm #post_url_link").blur(); 
    }); 
} 

回答

1

尝试

$(document).ready(function() { 
    $('.postForm').on('blur', '#post_title', function (e) { 
     alert('hi'); 
     $(".postForm #post_url_link").blur(); 
    }); 

    function postTitleCheck() { 
     $(".postForm #post_title").blur(); 
    } 
}); 

Don't Register the event handler in the function.As function is called a new event handler is registered every time which leads to many event handler.

例如

click 1 - handler count -1 
click 2 - handler count -2 
click 3 - handler count -3 
..... and so on 

和包装你的代码DOM ready handler

+0

作品,但我得到未捕获的ReferenceError:未定义postTitleCheck –

相关问题