gpt4 book ai didi

javascript - "SRC' ed”时是否可以访问脚本标签内容?

转载 作者:行者123 更新时间:2023-11-28 08:51:22 27 4
gpt4 key购买 nike

我做了一个简单的test(jsbin)与:

 <script id='a' type="text/javascript">
{a:1} //dummy value
var a=1;
</script>

然后:

alert($("#a").text());

结果是:

enter image description here

但是 - 使用 src 时有什么方法可以访问内容吗? 使用脚本标签

示例:

<script id='a' src="myjs.js" type="text/javascript"></script>

这似乎不起作用

换句话说:

if you have <script src="src">contents</script> - how to get "contents"

最佳答案

来自MDN ,

脚本标签

This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.

关于javascript - "SRC' ed”时是否可以访问脚本标签内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19110802/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com