简体   繁体   English

textContent无法读取所有文字

[英]textContent not reading all the text

I have an xml file on the disk that contains: 我的磁盘上有一个xml文件,其中包含:

<canvasTracking>
      <!-- GoStats JavaScript Based Code -->
      <script type="text/javascript" src="http://gostats.com/js/counter.js"></script>
      <script type="text/javascript">_gos='monster.gostats.com';_goa=458628;
      _got=5;_goi=1;_gol='Install live web stats on your site.';_GoStatsRun();</script>
      <noscript><a target="_blank" title="Install live web stats on your site." 
      href="http://gostats.com"><img alt="Install live web stats on your site." 
      src="http://monster.gostats.com/bin/count/a_458628/t_5/i_1/counter.png" 
      style="border-width:0" /></a></noscript>
      <!-- End GoStats JavaScript Based Code -->
</canvasTracking>

I read the file with: 我用以下方式读取文件:

$.post('loadSave.php', {saveName : xml_name},       
            function(xml) {  // loaded  data is in xml
                            canvas$ = $('#canvas');
                            if ($(xml).find("canvasTracking").length) {
                                canvasTracking  =  $(xml).find("canvasTracking")[0].textContent
                            }
                            else {
                                canvasTracking = '';
                            }

Looking at "xml" after the read I can see that all of the canvasTracking text came down, but after the 读取后查看“ xml”,我可以看到所有的canvasTracking文本都下降了,但是

canvasTracking  =  $(xml).find("canvasTracking")[0].textContent

line, canvasTracking contains only: 行,canvasTracking仅包含:

_gos='monster.gostats.com';_goa=458628;
_got=5;_goi=1;_gol='Install live web stats on your site.';_GoStatsRun();
<a target="_blank" title="Install live web stats on your site." 
href="http://gostats.com"><img alt="Install live web stats on your site." 
src="http://monster.gostats.com/bin/count/a_474698/t_5/i_1/counter.png" 
style="border-width:0" /></a>

Does anyone see the problem and know how I can get all the text? 有谁看到问题并知道我如何获得所有文本?

Thanks 谢谢

Try 尝试

var canvasTracking;
$.post('loadSave.php', {saveName : xml_name}
, function(xml) {
    if (xml.firstChild.nodeName === "canvastracking") {
      canvasTracking = $(xml.firstChild);
    } else {
      canvasTracking = ""
    }
    console.log(canvasTracking)
})

jsfiddle http://jsfiddle.net/guest271314/mm6yc1vh/ jsfiddle http://jsfiddle.net/guest271314/mm6yc1vh/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM