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>
<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>

作者:klvchen,发布于:2019/03/15
原文:https://www.cnblogs.com/klvchen/p/10538495.html