可能重复:
How may I reference the script tag that loaded the currently-executing script?
Can you select the script element that included the JavaScript?javascript可以引用创建它的脚本元素吗?
是否有任何identifyScript
,可以使这项工作? jQuery是太酷:
<script type="text/javascript" id="script1">
function identifyScript(){...}
</script>
<script type="text/javascript" id="script1">
identifyScript(); //This function would alert "script1"
</script>
<script type="text/javascript" id="script2">
identifyScript(); //This function would alert "script2"
</script>
不,这是不可能的,尽管您可以使用document.write在脚本内创建一个脚本后面的元素,只要脚本在初始页面呈现期间运行即可。 –
*为什么*你需要这样做?也许有一种更直接的方式来实现你的目标。 – hugomg
@missingno,这是那些只是很好的功能之一。插件配置可以移动到包含脚本上的属性。 – zzzzBov