相关文章推荐
稳重的警车  ·  jquery beforeunload方法 ...·  5 天前    · 
稳重的警车  ·  left join on ...·  1 周前    · 
稳重的警车  ·  .addClass() : ...·  10 月前    · 
稳重的警车  ·  UI-UIButton、UILable、UI ...·  11 月前    · 
稳重的警车  ·  android ...·  1 年前    · 
稳重的警车  ·  Bringing the x scroll ...·  1 年前    · 
帅气的红茶  ·  清华大学出版社·  2 小时前    · 
阳刚的凉面  ·  Python Web ...·  2 小时前    · 
傻傻的馒头  ·  利用Pycharm + ...·  2 小时前    · 
<!DOCTYPE html>
<html>
<head>
<style>
p { margin: 8px; font-size:16px; }
.selected { color:blue; }
.highlight { background:yellow; }
</style>
<script src="https://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p>Hello</p>
<p>and</p>
<p>Goodbye</p>
<script>
$("p").last().addClass("selected");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
p { margin: 8px; font-size:16px; }
.selected { color:red; }
.highlight { background:yellow; }
</style>
<script src="https://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p>Hello</p>
<p>and</p>
<p>Goodbye</p>
<script>
$("p:last").addClass("selected highlight");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div { background: white; }
.red { background: red; }
.red.green { background: green; }
</style>
<script src="https://code.jquery.com/jquery-latest.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>
 
推荐文章