开发者

jquery 1.5 .live issue with FF & IE9

I have a simple jquery function that utilize the .live function.

It applies to newly added element that is not there when $(document).ready

The function works in Chrome but not FF or IE.

The page is loading 1.5min

<script>
        $("#345").live("keypress", function(){
                if (event.which == '13') {
                        event.preventDefault();
                        $('#123').focus();
                }

});


$(document).ready(function(){
        $('#123').focus();
});


</script>

Edit: Also tried putting the .live code开发者_运维知识库s in the .ready function. Same result


You should not use numeric IDs, it's good practice to treat them as you would any identifiers in most programming languages.

You also left out the event parameter from your function definition in the first line:

$("#345").live("keypress", function(event){
    if (event.which == '13') {
        event.preventDefault();
        $('#123').focus();
    }
});

$(document).ready(function(){
    $('#123').focus();
});

It's also good practice not to wrap your jQuery in PHP strings, either close the PHP tag before and reopen it after, or restructure your code to prevent hard to debug quote issues. It would also do proper syntax highlighting in some text editors, making your job easier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜