添加多個屬性值僅適用於第一個,不知道爲什麼下面這種情況發生代碼:添加多個屬性值僅適用於第一個
jQuery("#gform_submit_button_1").attr({
style: "color: #fefefe !important",
style: "background-color: #000000 !important"
});
如果我改變自己的地方它仍然適用哪一個是第一。
添加多個屬性值僅適用於第一個,不知道爲什麼下面這種情況發生代碼:添加多個屬性值僅適用於第一個
jQuery("#gform_submit_button_1").attr({
style: "color: #fefefe !important",
style: "background-color: #000000 !important"
});
如果我改變自己的地方它仍然適用哪一個是第一。
裝在一個屬性:
jQuery("#gform_submit_button_1").attr({
style: "color: #fefefe !important; background-color: #000000 !important"
});
陳述2個不同style
標籤使秒一個重寫的第一個。如果您想更改多個屬性,必須通過他們在同一個style
標籤,或者您可以使用jQuery .css
而不是style
:
jQuery("#gform_submit_button_1").css({
"color":, "#fefefe !important",
"background-color": "#000000 !important"
});
這就是對象的方式工作。他們不允許有兩個值的一個關鍵:
console.log({
style: "color: #fefefe !important",
style: "background-color: #000000 !important"
});
所以,你可以加入他們在一起,這可以自動化:
var styles=["color: #fefefe !important","background-color: #000000 !important"];
jQuery("#gform_submit_button_1").attr({
style:styles.join(";")
});
由於生病記住這一點 – Zygimantas