jq-委托

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.hover{border:1px solid red;}
</style>
<script src="http://js.40017.cn/touch/cn/public/jquery-1.8.3.min.js"></script>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<input type="button" value="增加一个Li"/>
</body>
<script>
$("input").click(function(){
$("ul").append("<li>new</li>");
})


$("ul").delegate("li","hover",function(){
$(this).toggleClass("hover");
})
</script>
</html>
posted @ 2015-02-15 10:57  zhouyan_jsj  Views(92)  Comments(0Edit  收藏  举报