jQuery 常见属性操作方法 ******

 

1. toggleClass()

对设置或移除被选元素的一个或多个类进行切换。

个人理解:对所选元素做一个css样式更改。

eg:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").toggleClass("main");
});
});
</script>
<style type="text/css">
.main
{
font-size:120%;
color:red;
}
</style>
</head>

<body>
<h1 id="h1">This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button class="btn1">切换段落的 "main" 类</button>
</body>
</html>

 

posted on 2016-11-04 15:25  杜宝~  阅读(146)  评论(0编辑  收藏  举报

导航