jquery

老施同学 2016-06-06 11:11:40

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>addClass demo</title>
<style>
div {
background: white;
}
.red {
background: red;
}
.red.green {
background: green;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div>This div should be white</div>
<div class="red">This div will be green because it now has the "green" and "red" classes.
It would be red if the addClass function failed.</div>
<div>This div should be white</div>
<p>There are zero green divs</p>

<script>
$( "div" ).addClass(function( index, currentClass ) {
var addedClass;

if ( currentClass === "red" ) {
addedClass = "green";
$( "p" ).text( "There is one green div" );
}

return addedClass;
});
</script>

</body>
</html>

各位大大下边的这个函数看不懂。谁能教教我
...全文
105 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
___紫菜 2016-06-06
  • 打赏
  • 举报
回复
三个div分别执行那个函数,判断他们的样式,如果是red就改成green并且修改p标签的内容!

87,984

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧