簡體   English   中英

如何編寫jQuery以查找HTML元素ID屬性值並將該值設置為相同的HTML類屬性?

[英]How to write jquery to find html element id attribute value and set that value to same html class attribute?

當前嘗試編寫jQuery以查找html元素“ area”並獲取id屬性值並將該值設置為相同的html元素類屬性?

<map name="map">
<area id="test" />
.
.
.
//100 area tag
</map>

使用每個查找並遍歷所有區域標簽。 在回調內部,您可以使用$(this)引用當前區域。

$("area").each(function() {
    $(this).addClass($(this).attr("id"));
});
el = $(body).find("area");
$.each(el, function(key, element) {
    element.addClass(element.attr("id"));
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM