我需要删除innerHTML的某些部分。我现在已经尝试了3个小时了。看起来很简单。
这确实有用......
var foo = '<div id = "test" class = "hidden" style = "width: 350px"></div>';
alert(foo);
foo = foo.split('id = "test" class = "hidden" ').join('');
alert(foo);
这不是......
var myElement = document.getElementById('kjbggk');
myElement.innerHTML = '<div id = "test" class = "hidden" style = "width: 350px"></div>';
alert(myElement.innerHTML);
myElement.innerHTML = myElement.innerHTML.split('id = "test" class = "hidden" ').join('');
alert(myElement.innerHTML);
答案 0 :(得分:1)
Click here转到可能解决您问题的相关StackOverflow问题。
This question on SO似乎也与您的问题有关。
或者,你试过吗
var myElement = document.getElementById('kjbggk');
alert(myElement.innerHTML);
var foo = '<div id = "test" class = "hidden" style = "width: 350px"></div>';
alert(foo);
foo = foo.split('id = "test" class = "hidden" ').join('');
alert(foo);
myElement.innerHTML = foo;
alert(myElement.innerHTML);