jquery學習之二屬性(類)_jquery
來源:懂視網
責編:小采
時間:2020-11-27 20:55:57
jquery學習之二屬性(類)_jquery
jquery學習之二屬性(類)_jquery:addClass(class) 為每個匹配的元素添加指定的類名。 Adds the specified class(es) to each of the set of matched elements. 返回值 jQuery 參數 class (String) : 一個或多個要添加到元素中的CSS類名,請用空格分開 示例 為匹配的元素加
導讀jquery學習之二屬性(類)_jquery:addClass(class) 為每個匹配的元素添加指定的類名。 Adds the specified class(es) to each of the set of matched elements. 返回值 jQuery 參數 class (String) : 一個或多個要添加到元素中的CSS類名,請用空格分開 示例 為匹配的元素加

addClass(class)
為每個匹配的元素添加指定的類名。
Adds the specified class(es) to each of the set of matched elements.
返回值
jQuery
參數
class (String) : 一個或多個要添加到元素中的CSS類名,請用空格分開
示例
為匹配的元素加上 'selected' 類
HTML 代碼:
Hello
jQuery 代碼:
$("p").addClass("selected");
結果:
[
Hello
]
為匹配的元素加上 selected highlight 類
HTML 代碼:
Hello
jQuery 代碼:
$("p").addClass("selected highlight");
結果:
[
Hello
]
------------------------------------------------------------------------------------------------------------------------------
removeClass(class)
從所有匹配的元素中刪除全部或者指定的類。
Removes all or the specified class(es) from the set of matched elements.
返回值
jQuery
參數
class (String) : (可選) 一個或多個要刪除的CSS類名,請用空格分開
示例
從匹配的元素中刪除 'selected' 類
HTML 代碼:
Hello
jQuery 代碼:
$("p").removeClass("selected");
結果:
[
Hello
]
刪除匹配元素的所有類
HTML 代碼:
Hello
jQuery 代碼:
$("p").removeClass();
結果:
[
Hello
]
------------------------------------------------------------------------------------------------------------------------------
toggleClass(class)
如果存在(不存在)就刪除(添加)一個類。
Adds the specified class if it is not present, removes the specified class if it is present.
返回值
jQuery
參數
class (String) :CSS類名
示例
為匹配的元素切換 'selected' 類
HTML 代碼:
Hello
Hello Again
jQuery 代碼:
$("p").toggleClass("selected");
結果:
[
Hello
,
Hello Again
]
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
jquery學習之二屬性(類)_jquery
jquery學習之二屬性(類)_jquery:addClass(class) 為每個匹配的元素添加指定的類名。 Adds the specified class(es) to each of the set of matched elements. 返回值 jQuery 參數 class (String) : 一個或多個要添加到元素中的CSS類名,請用空格分開 示例 為匹配的元素加