zl程序教程

您现在的位置是:首页 >  后端

当前栏目

HTML 练习on方法

On方法HTML 练习
2023-09-27 14:26:01 时间
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<ul>
    <li>111</li>
    <li>222</li>
    <li>333</li>
    <li>444</li>
</ul>
<input type="button" value="+" onclick="add()">
<script>
    $("ul").on("click", "li", function(){
        alert(888)
    })

    function add(){
        $("ul").append("<li>555</li>")
    }
</script>
</body>
</html>

on方法,传递参数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<p>hello p</p>
</body>
<script>
    function myHandler(e){
        alert(e.data.foo)
    }
    $("p").on("click", {foo: "klvchen"}, myHandler)
</script>
</html>