[英]How to iterate over object with css properties and assign to style attribute?
這可能很簡單,但我無法弄清楚。
如何在下面的for循環中將對象值分配給按鈕樣式屬性?
(function(){
var parent = {
color: "orange",
width: "50px",
height: "50px"
},
child = Object.create(parent),
button = document.querySelector("button");
button.onclick = function(){
for (var test in child) {
button.style.test = // ??
}
}
})();
提前致謝
在這種情況下,會有方括號符號 :
button.style[test] = child[test];
更多: http : //www.javascripttoolbox.com/bestpractices/#squarebracket
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.