2013-04-10 71 views
2

我有這個選擇框:選擇框造型問題

<select class="slctbx condition-Combiner" onchange="updateConditionBuilder()" style="color: rgb(153, 153, 153);" disabled="disabled">

,我使用:

$('#rule-condition-listing tr:last-child .condition-Combiner').removeAttr("style","#999999").removeAttr("disabled","disabled");

因此它實際上消除禁用屬性,但不是顏色屬性

回答

2

.css() - 獲取匹配元素集合中第一個元素的style屬性的值,或爲每個匹配元素設置一個或多個CSS屬性。

$('#rule-condition-listing tr:last-child .condition-Combiner'). 
    css("color","#999999"). 
    removeAttr("disabled","disabled"); 

$('#rule-condition-listing tr:last-child .condition-Combiner'). 
    css("color",""). 
    removeAttr("disabled","disabled"); 
2

您必須將屬性名稱傳遞給removeAttr()但是您正在傳遞的名稱的值是不正確的語法,檢查語法removeAttr()here。您可以使用css()來設置顏色屬性。

$('#rule-condition-listing tr:last-child .condition-Combiner').css("color","").removeAttr("disabled","disabled"); 

而不是使用removeAttr,讓你也可以使用使用.attr(「禁用」,假)的元素;

2

如jquery的阿比單證所述,removeAttr - 功能只接受1分的條件。所以如果你做的事情如

$('#rule-condition-listing tr:last-child .condition-Combiner').removeAttr("style","#999999").removeAttr("disabled","disabled"); 

這意味着你刪除元素的樣式,'#999999'被丟棄。殘疾人部分也一樣。

我希望它有幫助。

親切的問候,亞歷克斯

2

不要混合屬性與造型。

在jQuery的你應該使用.css()屬性與造型工作,所以這應該工作

$('#rule-condition-listing tr:last-child .condition-Combiner').css("style","").removeAttr("disabled","disabled"); 
2

使用此:

$('#rule-condition-listing tr:last-child .condition-Combiner').css("color","").removeAttr("disabled","disabled");