我需要检查每个script
标记的src值,如果匹配,我想更改该脚本标记src属性......这样的事情:
var scripts = document.getElementsByTagName("script")[0].src
for (i=0;i<scripts.length;i++){
if(scripts[i] == "something.js"){
document.getElementsByTagName("script")[i].src = "this.js"
}
else {}
}}
答案 0 :(得分:8)
var scripts = document.getElementsByTagName("script");
for (i=0;i<scripts.length;i++){
if(scripts[i].src == "something.js"){
scripts[i].src = "this.js";
}
}