0

在这个小提琴中:http: //jsfiddle.net/m7q3H/52/

我正在访问 div“toupdate”中返回的 html。我希望它会返回, <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/6343621.js"></script> 而是返回:

 <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/6343621.js"></script><a name="pd_a_6343621" style="display: inline; padding: 0px; margin: 0px;"></a><div class="PDS_Poll" id="PDI_container6343621"><div style="margin-bottom: 0px; margin-top: 0px;" name="PDI_form6343621" id="PDI_form6343621"><div class="pds-box"><div class="pds-box-outer"><div class="pds-box-inner"><div class="pds-box-top"><div class="pds-question"><div class="pds-question-outer"><div class="pds-question-inner"><div class="pds-question-top"> New Poll</div></div></div></div><div class="pds-answer"><span id="pds-answer6343621"><span class="pds-answer-group"><span class="pds-answer-input"><input class="pds-radiobutton" type="radio" id="PDI_answer28688772" value="28688772" name="PDI_answer6343621"></span><label for="PDI_answer28688772" class="pds-input-label"><span class="pds-answer-span">Answer A</span></label><span class="pds-clear"></span><br></span><span class="pds-answer-group"><span class="pds-answer-input"><input class="pds-radiobutton" type="radio" id="PDI_answer28688773" value="28688773" name="PDI_answer6343621"></span><label for="PDI_answer28688773" class="pds-input-label"><span class="pds-answer-span">Answer B</span></label><span class="pds-clear"></span><br></span><span class="pds-answer-group"><span class="pds-answer-input"><input class="pds-radiobutton" type="radio" id="PDI_answer28688774" value="28688774" name="PDI_answer6343621"></span><label for="PDI_answer28688774" class="pds-input-label"><span class="pds-answer-span">Answer C</span></label><span class="pds-clear"></span><br></span></span></div><div class="pds-vote"><div class="pds-votebutton-outer"><a id="pd-vote-button6343621" class="pds-vote-button"><span>Vote</span></a><span class="pds-links"><a href="javascript:PD_vote6343621(1);" class="pds-view-results">View Results</a><br><a href="http://polldaddy.com/signup-free/?ad=poll-front" target="_blank" class="pds-pd-link">Polldaddy.com</a><span class="pds-clear"></span></span><span class="pds-clear"></span></div></div></div></div></div></div></div><img src="http://pixel.quantserve.com/pixel?a.1=p-18-mFEk4J448M&amp;a.2=p-ab3gTb8xb3dLg&amp;labels.1=type.polldaddy.poll" style="display: none;" border="0" height="1" width="1" alt="Quantcast"></div><div id="PD_superContainer"></div>

这段代码来自哪里?我可以通过单独的 jquery 方法而不是 .html() 访问所有这些 javascript 代码吗?

小提琴代码:

<body>
    <div id="toupdate">
    <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/6343621.js"></script>
    </div>

    </body>​

$(document).ready(function() {
    console.log('HTML is '+$('#toupdate').html());
});​
4

3 回答 3

4

它由 JS 输出http://static.polldaddy.com/p/6343621.js

.html()将实时 DOM 序列化为 HTML 的映射.innerHTML,它没有获取原始源。

如果您想要原始来源,您需要向文档的 URI 发出新的 HTTP 请求,然后将其作为文本处理。

于 2012-08-16T14:33:48.543 回答
2

该脚本有一些document.write()调用,它们被评估以向页面添加内容。

当浏览器看到该<script>标签时,它会加载脚本并立即执行代码。因此,脚本代码写入页面的内容最终会在该<div>元素内结束,因为结束标记尚未看到(浏览器)。

于 2012-08-16T14:34:07.950 回答
0

看起来脚本在里面生成了一些东西touupdate

在此处输入图像描述

于 2012-08-16T14:37:10.773 回答