如何在不使用jQuery的情況下從以下三個元素中返回Some Text
,<a href="abc.html">Some Anchor</a>
和<img src="abc.jpg" />
?換句話說,如何在不使用jQuery的情況下返回$('#t1).text()
,$('#t2).text()
,$('#t3).text()
?如果多個元素一次只選擇一個元素,我不需要返回數組。原生JavaScript equivilent單個選定元素的文本()
<td id="t1">Some Text</td>
<td id="t2"><a href="abc.html">Some Anchor</a></td>
<td id="t3"><img src="abc.jpg" /><td>
jQuery不會如下文字()。看起來有些過分,因爲我不擔心爲多個元素返回一個數組。
text: function(value) {
return jQuery.access(this, function(value) {
return value === undefined ?
jQuery.text(this) :
this.empty().append((this[0] && this[0].ownerDocument || document).createTextNode(value));
}, null, value, arguments.length);
},
感謝
'$( '#T2')'將返回'有些Anchor',不''
Can you just read the 'innerHTML' property after using 'document.getElementById()'? –
@CrazyJugglerDrummer. No, it will only work for the and
, not the text node. –
user1032531