我想檢查標籤是否有ID selected
。 我的html:按id選擇標籤內的元素,並檢查它的類 - 原型
<div id="30-super-attribute-138" class="colorswatch-lines">
<a class="lnk-colorswatch selected" id="30-lnk-colorswatch-138-34" href="javascript:selectColorSwatch(138, 34, 30, true)"></a>
</div>
和我的原型腳本:
if ($('30-super-attribute-138 a').hasClassName('selected')) {
var myStyle = '#333';
$('main-picture').setStyle ({
backgroundColor: myStyle
});
}
的setStyle工作正常,但我有麻煩來檢查,如果標籤a
有一流的選擇 - 它發生了,選擇後顏色。 在控制檯我看到錯誤:Uncaught TypeError: Cannot read property 'hasClassName' of null
請30-super-attribute-138
如何從內部DIV正確選擇標籤的ID爲謝謝彼得
...我將'.down('a')。hasClassName('selected')'修改爲'.down('a.selected')' – PeterB 2014-11-01 16:16:26