我有一个由Javascript填充的下拉列表.
在确定应该在加载时显示的默认值时,我意识到以下属性显示完全相同的值:
innerTextinnerHtmllabeltexttextContentouterText我自己的研究显示了基准测试或其中几个测试之间的比较,但不是全部.
我可以使用我自己的常识并选择1或其他因为它们提供相同的结果,但是,我担心如果数据要改变,这不是一个好主意.
我的发现是:
innerText 将按原样显示该值,并忽略可能包含的任何HTML格式innerHTML 将显示该值并应用任何HTML格式label看来是一样的innerText,我看不出差别text似乎innerText与jQuery简写版本相同textContent看起来像是一样innerText但保持格式化(例如\n)outerText 似乎是一样的 innerText我的研究只能采取我太厉害,我只能考什么我能想到的或读到的东西发布后,任何一个可以确认但如果我的研究是正确的,如果有什么特别的label和outerText?
当我需要更改span元素中的文本时,我应该使用哪个文本以及区别:
var spnDetailDisplay=document.getElementById('spnDetailDisplay');
spnDetailDisplay.innerText=sDetail;
Run Code Online (Sandbox Code Playgroud)
要么
var spnDetailDisplay=document.getElementById('spnDetailDisplay');
spnDetailDisplay.childNodes[0].nodeValue=sDetail;
Run Code Online (Sandbox Code Playgroud) 我正在玩jQuery .text()和.html()方法并运行一些简单的jsPerf测试,当我惊讶地发现.html()在检索文本时要快得多:
$div.text() - 88,496次/秒$div.html() - 592,028次/秒为什么.text()比.html()结果相同时要慢得多?什么操作.text()可以.html()跳过来解释这种差异?
我知道每种方法都有不同的目的; 我很好奇他们用于同一目的的情况.
我无法gettext在selenium中找到以下代码webdriver.
<a id="551" class="blueTextNormal1 spc" onclick="sPh(this,'079');return false;" title="079">Country</a>
Run Code Online (Sandbox Code Playgroud)
我想获得Country的价值.我尝试使用xpath
driver.findElement(By.xpath("//*[@id='551']").getText())
Run Code Online (Sandbox Code Playgroud)
但它没有返回任何价值.我试过的时候
driver.findElement(By.xpath("//*[@id='551']")).getAttribute("title"))
Run Code Online (Sandbox Code Playgroud)
我得到的值是"079"
任何人都可以建议如何进行的想法.
我正在尝试从 XML 字符串中检索“代码”和“值”。
我有以下 XML 字符串:
<items>
<item>
<id>55</id>
<attributes>
<attribute>
<code>ID</code>
<value><![CDATA[55]]></value>
</attribute>
<attribute>
<code>Chip_ID</code>
<value><![CDATA[1]]></value>
</attribute>
<attribute>
<code>FilterKey</code>
<value><![CDATA[5]]></value>
</attribute>
<attribute>
<code>DateTime</code>
<value><![CDATA[22/12/2014 12:21:25]]></value>
</attribute>
</attributes>
</item>
</items>
Run Code Online (Sandbox Code Playgroud)
然后我有以下 javaScript 来标识每个节点:
var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
xmlDocument.async = false;
xmlDocument.loadXML(pXML);
var oFirstNode = xmlDocument.documentElement;
var item = oFirstNode.childNodes[0]; //10 of these and they represent the items
//alert("1 "+item.nodeName);
var ID = item.childNodes[0]; //one of these for each level-ID - NO CHILDREN
var attributes = item.childNodes[1]; //one of these …Run Code Online (Sandbox Code Playgroud)