innerText 跟 innerHTML是两个非DOM标准的方法
其区别如图所示:
其区别如图所示:
在IE中 innerText 跟 innerHTML 两个方法都能正常运行
但是FF里面的innerText不可用,但是有一个替代方法: textContent
IE: oDiv.innerText = aString; oDiv.innerHTML = aString;
FF: oDiv.textContent = aString; oDiv.innerHTML = aString;
但是FF里面的innerText不可用,但是有一个替代方法: textContent
IE: oDiv.innerText = aString; oDiv.innerHTML = aString;
FF: oDiv.textContent = aString; oDiv.innerHTML = aString;
innerHTML,outerHTML,innerText,outerText这些都是相对于某个标签的id而言的,以下代码是可以直接运行看到区别的:
<div id="div">
<font color="green"><h2>THis is Div</h2></font>
</div>
<input type="button" name="innerHTML" value="innerHTML" onclick="alert(div.innerHTML);"/>
<input type="button" name="outerHTML" value="outerHTML" onclick="alert(div.outerHTML);"/>
<input type="button" name="innerText" value="innerText" onclick="alert(div.innerText);">
<input type="button" name="outerText" value="outerText" onclick="alert(div.outerText);">
<font color="green"><h2>THis is Div</h2></font>
</div>
<input type="button" name="innerHTML" value="innerHTML" onclick="alert(div.innerHTML);"/>
<input type="button" name="outerHTML" value="outerHTML" onclick="alert(div.outerHTML);"/>
<input type="button" name="innerText" value="innerText" onclick="alert(div.innerText);">
<input type="button" name="outerText" value="outerText" onclick="alert(div.outerText);">
(1)name="innerHTML"运行结果:
(2)name="outerHTML"运行结果:
(3)name="innerText"与name="outerText"运行结果:
========================================================================
Freemarker code:
<td class="tdFormText" width="20%">姓 名:</td>
<td class="tdFormInput" width="30%"><@ww.textfield name="'appealMail.name'" id="name" cssClass="'inputTextNormal'" tabindex="'2'" disabled ="'${showState}'" onblur="'return checkusername()'"/><font color="C90E00">* <label id="username"></label></td>
<td class="tdFormInput" width="30%"><@ww.textfield name="'appealMail.name'" id="name" cssClass="'inputTextNormal'" tabindex="'2'" disabled ="'${showState}'" onblur="'return checkusername()'"/><font color="C90E00">* <label id="username"></label></td>
function checkusername(){
var checkname = document.getElementById('name').value;
if(checkname==''){
document.getElementById('username').innerText="请输入姓名!";
return false;
}
document.getElementById('username').innerText="";
return true;
}
var checkname = document.getElementById('name').value;
if(checkname==''){
document.getElementById('username').innerText="请输入姓名!";
return false;
}
document.getElementById('username').innerText="";
return true;
}
本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/354159,如需转载请自行联系原作者