Jquery how to bind click event on dynamically crea

2020-01-29 02:23发布

I tried the below code but it is not working

<script type="text/javascript">
    $(document).ready(function () {
        $('body').on('click', '.pg_previous,.pg_next', function () {
            jQuery("img.lazy").lazy({});
            alert('ddsda');
        });
    });
</script>

Jquery 1.9.1

2条回答
我命由我不由天
2楼-- · 2020-01-29 02:46

You forgot the DOM ready handler

Encase your code inside the ready handler and should work fine unless you have any errors showing up in our console.

$(function() {
    // Your code here
});
查看更多
放荡不羁爱自由
3楼-- · 2020-01-29 02:48

here try this:

<script type="text/javascript">
$(function(){
    $('body').on('click', '.pg_previous,.pg_next', function () {
        jQuery("img.lazy").lazy({});
        alert('ddsda');
    });
});
</script>
查看更多
登录 后发表回答