将脚本内容作为文本获取 [英] Get content inside script as text

查看:118
本文介绍了将脚本内容作为文本获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用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>
​

http://jsfiddle.net/UBw44/

这篇关于将脚本内容作为文本获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆