当我需要更改一个span元素中的文本时,我应该使用哪个文本,有什么区别:
var spnDetailDisplay=document.getElementById('spnDetailDisplay'); spnDetailDisplay.innerText=sDetail;
要么
var spnDetailDisplay=document.getElementById('spnDetailDisplay'); spnDetailDisplay.childNodes[0].nodeValue=sDetail;
解决方法
对于具有文本内容的元素,它们是一样的.有关nodeValue的信息,请参见
this MDC article.
If the element has no sub-elements,just text,then it (normally) has one child node,accessed as
ElemRef.childNodes[0]
. In such precise case,the W3C web standards equivalent ofElemRef.innerText
isElemRef.childNodes[0].nodeValue
.