我有一个这样的网页
<html>
<head>
<script type="script/text" src="http://www.seantburke.com/j.js"></script>
<script type="script/text">
$(document).ready({var foo;});
</script>
</head>
<body>
<script>
var s = "some more javascript here";
</script>
<script type="script/text" src="http://www.seantburke.com/otherjs.js"></script>
</body>
</html>
我想从页面中选择所有脚本,包括属性和innerHTML作为文本。我缺少一个简单的jQuery函数吗?
所需的输出:
<script type="script/text"
src="http://www.seantburke.com/j.js"></script><script
type="script/text">$(document).ready({var foo;});</script><script>var
s = "some more javascript here";</script><script type="script/text"
src="http://www.seantburke.com/otherjs.js"></script>
这些是我尝试获得的尝试,但均未获得所需的输出:
$('script').text() //gives all innerHTML
$('script') //gives an Array of HTMLScriptElement
$('script')[0].outerHTML //gives the outerHTML as a string for only the first element.
var arr = $('script').map(function() {
return this.outerHTML;
}).get();
如果要使用单个字符串,则为您获取每个标记的所有externalHTML数组 arr.join()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句