jquery

老施同学 老施同学 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

<!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>

各位大大下边的这个函数看不懂。谁能教教我
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
老施同学
JavaScript 87,983 成员 224,681 内容