jquery 1.9.1 on event not working



随着Jquery v1.5.2以下功能的工作,我已经将Jquery升级到1.9.1 live已经替换为上的功能。如果我把live换成on。

我更改了live并包含了迁移插件。如何在函数

上使用
$( ".pop-up" ).live(
                        "click",
                            function( event ){
                                // get the id of the item clicked on
                                var id = $(this).attr('id');
                                 alert(id)
                            // block the href actually working
                            return( false );
                            });

试试这个

你可以使用DOM中已经存在的选择器来代替document,如果这个元素在以后的时间被动态地添加到DOM中。

$(function(){
      $(document).on("click", ".pop-up",
        function( event ){
                            // get the id of the item clicked on
                            var id = $(this).attr('id');
                             alert(id)
                        // block the href actually working
                        return( false );
       });
});

最新更新