通过 jquery 更改 css 链接的 href
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3829687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:11:31 来源:igfitidea点击:
change the href of a css link via jquery
提问by Omu
<head>
<link href="foo.css" rel="stylesheet" type="text/css" />
</head>
can I via jquery change the href of this link from foo.css
to bar.css
我可以通过 jquery 将此链接的 href 从更改foo.css
为bar.css
回答by Lasse Espeholt
Html:
网址:
<head>
<link id="test" href="foo.css" rel="stylesheet" type="text/css" />
</head>
<body>
...
</body>??????????
And the jQuery:
和 jQuery:
?$(document).ready(function() {
$("#test").attr("href", "bar.css");
});?
回答by Hannes
$('link[href="foo.css"]').attr('href','bar.css');
have fun
玩得开心
回答by infoexpert.it
And one more
还有一个
Html:
网址:
<head>
<link id="bar" href="foo.css" rel="stylesheet" type="text/css"/>
</head>
jQuery:
jQuery:
$("link[id='bar']").attr('href', 'bar.css');