Javascript innerText v.s innerHTML

Javascript innerText v.s innerHTML

Javascript innerText v.s innerHTML

test : <font color="blue">OriginalFont_1</font>

innerHTML: OriginalFont_1

innerText : <font color="blue">OriginalFont_1</font>

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function ChangeString(){
    var NewStringValue=document.getElementById("StringTextBox").value;
    document.getElementById("NewStringBox").innerHTML=NewStringValue;
}
function ChangeString2(){
    var NewStringValue=document.getElementById("StringTextBox").value;
    document.getElementById("NewStringBox").innerText=NewStringValue;
}
</script>
<p id="NewStringBox">請輸入新的文字來改變這段文字</p>
<input type="text" id="StringTextBox">
<input type="button" value="變更文字_innerHTML" onclick="ChangeString()">  
<input type="button" value="變更文字_innerText" onclick="ChangeString2()">
</body>
</html>

 

 

參考網址: http://www.wibibi.com/info.php?tid=402