我想在同一个jsp上使用javascript变量作为另一个标记的'src'属性.
<script>
var link = mylink // the link is generated based on some code
</script>
Run Code Online (Sandbox Code Playgroud)
我想创建这个新元素,如下所示.
<script src="mylink">
</script>
Run Code Online (Sandbox Code Playgroud)
在搜索各种论坛时,我尝试使用以下选项,但它们似乎不起作用.我希望这个东西适用于所有主流浏览器.
将此代码放在第一个元素中.
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "path/to/somelink";
document.body.appendChild(script);
Run Code Online (Sandbox Code Playgroud)在第一个元素中使用document write方法.
document.write("<script type='text/javascript' src="+ google.com + "><\/script>");
Run Code Online (Sandbox Code Playgroud)试图在第一个元素中设置JSTL变量并使用它.
<c:set var="URL" value="mylink"/>
Run Code Online (Sandbox Code Playgroud)这些方法都没有成功.什么是错误的任何建议?