<style>
div?{
color:?red;
text-align:?center;
cursor:?pointer;
font-weight:?bolder;
width:?300px;
}
</style>
<script?src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
</head>
<body>
<div>Click?here</div>
<div>to?iterate?through</div>
<div>these?divs.</div>
<script>
$(document.body).click(function()?{
$(?"div"?).each(function(?i?)?{
if?(?this.style.color?!==?"blue"?)?{
this.style.color?=?"blue";
}?else?{
this.style.color?=?"";
}
});
});
</script>這里使用的是document.body ? ?為什么點(diǎn)擊body沒(méi)效果,換成document有效果,單純使用body會(huì)報(bào)錯(cuò),然后里面使用的是this,不是$(this)
- 1 回答
- 0 關(guān)注
- 1890 瀏覽
添加回答
舉報(bào)
0/150
提交
取消