gpt4 book ai didi

jQuery。各种项目的前缀选择器

转载 作者:行者123 更新时间:2023-12-01 04:55:07 25 4
gpt4 key购买 nike

如何优化这个?

$('link[href="dir/style.css"]').attr("href", "dir/style2.css");
$('link[href="../../dir/style.css"]').attr("href", "../../dir/style2.css");
jQuery('link[href="../dir/style.css"]').attr("href", "../dir/style2.css");

最佳答案

这应该在使用 attribute ends with selectorattr 的单次调用中执行相同的操作:

$('link[href$="style.css"]').attr('href', function(index, value) {
return value.replace('style.css', 'style2.css');
});

JSFiddle Example

关于jQuery。各种项目的前缀选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953585/

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