首页 > 代码库 > 事件委托

事件委托

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
    <ul id="ul1">
        <li>111</li>
        <li>222</li>
        <li>333</li>
        <li>444</li>
    </ul>
</body>
<script src="jquery-1.12.4.min.js"></script>
<script>
        var oUl = document.getElementById("ul1");
        var aLi = oUl.getElementsByTagName(li);
        $(document).on(click,li,function(){
            alert("hello");
        })
        $(oUl).append("<li>demo</li>");
</script>
</html>

 

事件委托