Javascript 如何在博客脚本的url中使用变量

Javascript 如何在博客脚本的url中使用变量,javascript,blogger,Javascript,Blogger,我想用外部提要替换blogger提要 所以我制作了一个JSON提要,并在调用函数中扭曲,保存在外部服务器中 我替换了默认的提要 <script expr:src='data:blog.canonicalHomepageUrl + &quot;/feeds/posts/summary/?alt=json-in-script&amp;redirect=false&amp;start-index=1&amp;max-results=200&amp;call

我想用外部提要替换blogger提要 所以我制作了一个JSON提要,并在调用函数中扭曲,保存在外部服务器中 我替换了默认的提要

<script expr:src='data:blog.canonicalHomepageUrl + &quot;/feeds/posts/summary/?alt=json-in-script&amp;redirect=false&amp;start-index=1&amp;max-results=200&amp;callback=related_posts&quot;'/>

'
它工作得很好,但我想在URL中使用变量来更改 feed1.js。。。。。feed4.js 所以我想在脚本URL中添加从1到4的变量 怎么做

我试过了,但没用

<script expr:src='&quot;https://example.com/feed&quot; + variable + &quot;.js&quot;'/>


有什么想法吗?

您需要使用JavaScript来实现这一点。您需要创建
计数器
,并根据需要增加值(这里我使用的是一个按钮)。然后相应地更新脚本的
src

let script=document.querySelector(“脚本”);
设计数器=1;
script.src=`https://example.com/feed${counter}.js`
log(script.src)
document.querySelector(“.btn”).onclick=function(){
计数器++;
script.src=`https://example.com/feed${counter}.js`
log(script.src)
}
'

更改
如果条件限制计数器,则需要启用

<script expr:src='&quot;https://example.com/feed&quot; + variable + &quot;.js&quot;'/>