我放在函数里面的innerHtml出现未知错误,但是外面的好好的
<textarea name= "pc " rows= "20 " cols= "50 "> </textarea>
<input type= "button " onclick= "myFunc() " value= "改变颜色! " />
<script language= "JavaScript ">
var oB = document.createElement( "Div ");
oB.innerHTML = " <font color= 'red '> 红色 </font> ";
document.getElementById( "pc ").appendChild(oB);
function myFunc()
{
alert(oB.innerHTML);//这句话的结果显示正确
oB.innerHTML = " <font color= 'green '> 绿色 </font> "; //ie提示出错了
}
</script>
------解决方案-------------------- <textarea name= "pc " rows= "20 " cols= "50 "> </textarea>
<input type= "button " onclick= "myFunc() " value= "改变颜色! " />
<script language= "JavaScript ">
var oB = document.createElement( "Div ");
oB.innerHTML = " <font color= 'red '> 红色 </font> ";
document.getElementById( "pc ").appendChild(oB);
var font = document.createElement( "FONT ");
function myFunc()
{
alert(oB.innerHTML);//这句话的结果显示正确
//oB.innerHTML = " <font color= 'green '> 绿色 </font> "; //ie提示出错了
oB.innerHTML = " ";
font.color = "green ";
font.innerText = "绿色 ";
oB.appendChild(font);
alert(oB.innerHTML);
}
</script>