本文介绍了将脚本内容作为文本获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用jquery打印脚本标签的内容吗?
I would like to print the content of a script tag is that possible with jquery?
index.html
index.html
<script type="text/javascript">
function sendRequest(uri, handler)
{
}
</script>
代码
alert($("script")[0].???);
结果
function sendRequest(uri, handler)
{
}
推荐答案
只需给你的脚本标签一个id:
Just give your script tag an id:
<div></div>
<script id='script' type='text/javascript'>
$('div').html($('#script').html());
</script>
这篇关于将脚本内容作为文本获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!