如何将javascript变量传递给javascript src链接

时间:2019-03-22 08:10:32

标签: javascript

如何将javascript变量传递给javascript src链接

我想传递变量myoutput,以变量值替换YOUR_LABEL_HERE

我的代码:

 <script>
    var myoutput = 'Diet';
</script>
<script src="/feeds/posts/default/-/YOUR_LABEL_HERE?published&amp;alt=json-in-script&amp;callback=labelthumbs" type='text/javascript'> </script>    

1 个答案:

答案 0 :(得分:0)

给它一个let now = new Date() console.log(now) let last30days = new Date(now.setDate(now.getDate() - 30)) console.log(last30days),然后可以像其他任何元素一样将其作为目标,然后更改其id

(检查代码段的结果以查看更改)

src
const theScript = document.getElementById("changeMySrc"),
      theVariable = "something"

theScript.src = "http://somesite.com/" + theVariable + "/urlEnd"

脚本现在为<script id="changeMySrc"></script>