Tôi đang cố gắng thay thế giá trị thẻ kiểu nội tuyến của phần tử. Phần tử hiện tại trông giống như sau:xoá kiểu phần tử html qua javascript
`<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">`
và tôi muốn xóa tất cả nội dung theo phong cách của nó chứ không phải kiểu nội tuyến. Tôi đã thử xóa element.style; và element.style = null; và element.style = ""; không có kết quả. Mã hiện tại của tôi vi phạm tại các tuyên bố này. Toàn bộ chức năng trông giống như:
chức năng 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");
}
các clearInterval hoạt động nhưng cảnh báo không bao giờ cháy và nền vẫn như cũ. Bất cứ ai nhìn thấy bất kỳ vấn đề? Cảm ơn trước ...
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");
}
Cố gắng removeAttribute ("phong cách"), vẫn không có may mắn. Tôi đang sử dụng setInterval để chuyển qua màu nền để (cố gắng) tạo hiệu ứng xung. Tôi sẽ thử viết một số lớp phong cách khác để thử trả lời 4. Có ý tưởng nào khác không? Mã hiện tại của tôi được đăng bên dưới ... – danwoods
nó sẽ là tuyệt vời nếu bạn chấp nhận [this] (http://stackoverflow.com/a/1040439/2008111) là câu trả lời đúng cho câu hỏi này – caramba
^Nó không phải là câu trả lời đúng , Tuy nhiên. –