How to get the nodes inner text in java script?

I have a string of XML format. As shown below:

<gt>
    <st>sample1</st>
    <tt>sample2</tt>                    
    <tt>sample3</tt>
</gt>

I need to get the node value in Java script file. How can I get the value?


Try this code:

var xml = "<gt><st>sample1</st><tt>sample2</tt><tt>sample3</tt></gt>",
    xmlDoc = $.parseXML(xml),
    $xml = $( xmlDoc ),
    $st = $xml.find( "st" );

alert( $st.text() );

See the js fiddle example


Use .parseXML() .

var xmldom = $.parseXML('<gt><st>sample1</st><tt>sample2</tt><tt>sample3</tt></gt>');

console.log($(xmldom).find('gt *'));

This will find all nodes under <gt> .

链接地址: http://www.djcxy.com/p/59812.html

上一篇: 使用ruby SDK将S3 bucket设置为网站

下一篇: 如何获得Java脚本中的节点内部文本?