返回值:jQuerytoggleClass(class, switch)
概述
如果開(kāi)關(guān)switch參數(shù)為true則加上對(duì)應(yīng)的class,否則就刪除。
參數(shù)
classString
要切換的CSS類名
switchBoolean
用于決定元素是否包含class的布爾值。
示例
描述:
每點(diǎn)擊三下加上一次 'highlight' 類
HTML 代碼:
<strong>jQuery 代碼:</strong>
jQuery 代碼:
var count = 0;
$("p").click(function(){
$(this).toggleClass("highlight", count++ % 3 == 0);
});