当我需要更改一个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
.
原文地址:https://www.jb51.cc/html/231282.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。