我有一個HTML標籤:如何檢查「for」prop prop excists的標籤?
<label class="label-radio-button-detail-gray" for="Metallic Black">
</label>
和陣列我從一個ajax交還給我:
Array [ "Metallic Black" ]
我要檢查,如果有一個標籤=「金屬黑」在頁面上的excists然後添加一個類。
這是我有:
).done(function(response){
console.log(response);
if(response.length > 0) {
response.forEach(function(item){
});
}
});
我如何實現這一目標?
'金屬Black'不是for'的'有效值:_ 「如果指定了屬性,該屬性的值必須是一個貼標籤的元素的ID」 _([W3 ](https://www.w3.org/TR/html5/forms.html#attr-label-for)),並且不允許包含空格:_「當在HTML元素上指定時,id屬性值必須在元素樹中的所有ID中必須是唯一的,並且必須至少包含一個字符。該值不能包含任何ASCII空格。「_([HTML Standard](https://html.spec.whatwg.org/multipage/dom .html#the-id-attribute)) – Andreas