【发布时间】:2010-11-05 15:20:58
【问题描述】:
我正在尝试替换元素的内联样式标记值。当前元素如下所示:
`<tr class="row-even" style="background: red none repeat scroll 0% 0%; position: relative; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" id="0000ph2009-06-10s1s02">`
我想删除所有那些样式的东西,以便它的样式由它的类而不是它的内联样式。我试过删除 element.style;和 element.style = null;和 element.style = "";无济于事。我当前的代码在这些语句中中断。整个函数看起来像:
函数 unSetHighlight(index){
if(index < 10)
index = "000" + (index);
else if (index < 100)
index = "000" + (index);
else if(index < 1000)
index = "0" + (index);
if(index >= 1000)
index = index;
var mainElm = document.getElementById('active_playlist');
var elmIndex = "";
for(var currElm = mainElm.firstChild; currElm !== null; currElm = currElm.nextSibling){
if(currElm.nodeType === 1){
var elementId = currElm.getAttribute("id");
if(elementId.match(/\b\d{4}/)){
elmIndex = elementId.substr(0,4);
if(elmIndex == index){
var that = currElm;
//that.style.background = position: relative;
}
}
}
}
clearInterval(highlight);
alert("cleared Interval");
that.style.background = null;
alert("unSet highlight called");
}
clearInterval 有效,但警报永远不会触发并且背景保持不变。有人看到任何问题吗?提前谢谢...
function unSetHighlight(index){
alert(index);
if(index < 10)
index = "000" + (index);
else if (index < 100)
index = "000" + (index);
else if(index < 1000)
index = "0" + (index);
if(index >= 1000)
index = index;
var mainElm = document.getElementById('active_playlist');
var elmIndex = "";
for(var currElm = mainElm.firstChild; currElm !== null; currElm = currElm.nextSibling){
if(currElm.nodeType === 1){
var elementId = currElm.getAttribute("id");
if(elementId.match(/\b\d{4}/)){
elmIndex = elementId.substr(0,4);
alert("elmIndex = " + elmIndex + "index = " + index);
if(elmIndex === index){
var that = currElm;
alert("match found");
}
}
}
}
clearInterval(highlight);
alert("cleared Interval");
that.removeAttribute("style");
//that.style.position = "relative";
//reColor();
alert("unSet highlight called");
}
【问题讨论】:
-
试过 removeAttribute("style"),还是不行。我正在使用 setInterval 循环显示背景颜色以(尝试)创建脉冲效果。我将尝试编写一些其他样式类来尝试回答 4。还有其他想法吗?我当前的代码发布在下面...
-
如果你能接受this作为这个问题的正确答案,那就太好了
-
^但这不是正确的答案。
标签: javascript html dom styles