gpt4 book ai didi

jquery - 如何使用 jQuery 查找特定脚本

转载 作者:行者123 更新时间:2023-12-01 03:19:32 25 4
gpt4 key购买 nike

我想查看我的 html 文件并查找特定脚本是否存在。

我写了这段代码:

var scriptExist = false;
$('script').each(function(i,e){
if( $(e).attr('src')){
if( $(e).attr('src').search("load.js)!=-1){
scriptExist = true;
return false;
}
}
});
return scriptExist;
},

可以在 jQuery 中执行此 lofic 操作,而无需使用 use.each 并找到特定的脚本,例如 src = load.js ?

最佳答案

试试这个:

$('script').filter(function(){
return $(this).attr('src') === "load.js"
})

或者您可以使用attribute contains selector :

Selects elements that have the specified attribute with a value containing the a given substring.

$('script[src*="load.js"]')  

关于jquery - 如何使用 jQuery 查找特定脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11412856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com