【问题标题】:change the href of a css link via jquery通过 jquery 更改 css 链接的 href
【发布时间】:2013-01-17 23:00:56
【问题描述】:
<head>
<link href="foo.css" rel="stylesheet" type="text/css" />
</head>

我可以通过 jquery 将此链接的 href 从 foo.css 更改为 bar.css

【问题讨论】:

    标签: jquery html


    【解决方案1】:
    $('link[href="foo.css"]').attr('href','bar.css');
    

    玩得开心

    【讨论】:

    • 太棒了——正是我所需要的!
    【解决方案2】:

    HTML:

    <head>
    <link id="test" href="foo.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        ...
    </body>​​​​​​​​​​
    

    还有 jQuery:

    ​$(document).ready(function() {
        $("#test").attr("href", "bar.css");
    });​
    

    【讨论】:

    【解决方案3】:

    还有一个

    HTML:

    <head> 
    <link id="bar" href="foo.css" rel="stylesheet" type="text/css"/> 
    </head>
    

    jQuery:

    $("link[id='bar']").attr('href', 'bar.css');
    

    【讨论】:

      猜你喜欢
      • 2012-12-17
      • 1970-01-01
      • 2019-12-03
      • 2011-01-06
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 2013-05-01
      • 2012-05-17
      相关资源
      最近更新 更多