我試圖將嵌入樣式添加到具有特定計算樣式屬性的頁面中的元素。Javascript:爲具有特定計算樣式屬性的頁面中的元素添加嵌入樣式
例如:
<head>
<style>
p.mim {
cursor:pointer;
}
a.fif {
cursor:pointer;
}
</style>
</head>
<body>
<p class="mim">prova</p>
<a class="fif">prova</a>
</body>
我想補充一個內嵌式的「光標:等待」到了每一個元素「光標:指針」設定在計算樣式:
<body>
<p class="mim" style="cursor:wait;">prova</p>
<a class="fif" style="cursor:wait;">prova</a>
</body>
這是我嘗試過的:
var elms = document.getElementsByTagName("*");
for (var j = 0; j < elms.length; j++) {
var crs = getComputedStyle(elm, null).getPropertyCSSValue('cursor') || "";
crs = crs.replace(/\s/g, "").toLowerCase();
switch (crs) {
case "pointer":
case "Pointer":
case "POINTER":
elm.style.cursor = "wait";
break;
}
});
是否有某種原因讓'});'最後? –