<1>hasClass 应用
Examples:
HTML
<div id="myElement" class="testClass"></div>
JavaScript
$('myElement').hasClass('testClass'); // returns true
<2>addClass 应用
Examples:
HTML
<div id="myElement" class="testClass"></div>
JavaScript
$('myElement').addClass('newClass');
<3>removeClass 应用
Examples:
HTML
<div id="myElement" class="testClass newClass"></div>
JavaScript
$('myElement').removeClass('newClass');
Resulting HTML
<div id="myElement" class="testClass"></div>
<4>toggleClass 应用
Adds or removes the passed in class name to the Element, depending on whether or not it's already present.
Examples:
HTML
<div id="myElement" class="myClass"></div>
JavaScript
$('myElement').toggleClass('myClass');
Resulting HTML
<div id="myElement" class=""></div>
JavaScript
$('myElement').toggleClass('myClass');
Resulting HTML
<div id="myElement" class="myClass"></div>
posted on 2011-01-11 22:21
冯占科 阅读(1289)
评论(0) 编辑 收藏