这样可以吗
来源:4-8 事件委托或代理
qq_白色约定_0
2019-10-11 15:27:48
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style>
.red{
background: red;
}
</style>
<button class="two">添加</button>
<ul class=" one">
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
</ul>
<script src="https://zeptojs.com/zepto.min.js"></script>
<script>
$(".two").bind("click" , function(){
$(".one").append('<li>555</li>')
})
$(".one").on("mouseover","li" ,function(){
$(this).addClass("red")
}).bind("mouseleave" ,"li", function(){
$(this).removeClass("red");
})
</script>
</body>
</html>
1回答
好帮手慕糖
2019-10-11
同学你好,第四个是444,第五个是555,那个第六个应该是666哦。
但是同学这里一直是555哦。建议:可以设置获取当前的长度,然后点击的时候,让长度+1,然后乘以111,例:
希望能帮助到你,欢迎采纳。
祝学习愉快!
相似问题