jQuery-模拟操作

trigger()--打开页面不需要操作,就可以触发事件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src='jquery-3.2.1.min.js'></script>
    <script type="text/javascript">
        $(function(){
            $('#btn').one('click',function(){
                $('#test').append('<p>我的绑定函数1</p>');
            }).one('click',function(){
                $('#test').append('<p>我的绑定函数2</p>');
            }).one('click',function(){
                $('#test').append('<p>我的绑定函数3</p>');
            });
            $('#btn').trigger('click');  //一打开页面,就触发click事件
        });
    </script>
</head>
<body>
    <button id="btn">单击我</button>
    <button id="delAll">删除所有事件</button>
    <div id="test"></div>
</body>
</html>

 

posted @ 2017-05-18 20:02  影子疯  阅读(144)  评论(0编辑  收藏  举报