我正在尝试替换一个元素的内联样式标签值。当前的元素看起来像这样:
我想删除所有的样式内容,使其通过类别而不是内联样式进行样式设置。我尝试了删除element.style; 和 element.style = null; 以及 element.style = ""; ,但都没有成功。我的当前代码在这些语句处出现错误。整个函数如下:
function unSetHighlight(index){
clearInterval可以正常工作,但是警告框从未触发,背景保持不变。问题出在哪里?
`<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 = ""; ,但都没有成功。我的当前代码在这些语句处出现错误。整个函数如下:
function 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");
}