【问题标题】:jQuery change innerHTML of link based on hrefjQuery基于href改变链接的innerHTML
【发布时间】:2014-06-27 07:08:44
【问题描述】:

我有以下由 CMS 为选项卡式元素生成的 html:

<li class="active" style="width: 233px;">
  <a href="#tabopen_tickets">Open Tickets</a>
</li>

我想把“Open Tickets”的link's文字改成其他文字,但我只知道链接的href

如何用 jQuery 做到这一点?谢谢!

【问题讨论】:

标签: javascript jquery html innerhtml


【解决方案1】:
$('a[href="#tabopen_tickets"]').html('your new value');

【讨论】:

    【解决方案2】:

    试试

    Attribute Equals Selector [name="value"]

    $('a[href="#tabopen_tickets"]').text('Changed');
    

    $('a[href="#tabopen_tickets"]') 将选择带有href 属性#tabopen_tickets"a 标签

    【讨论】:

    • 感谢使用 text():我讨厌人们使用 html() 插入文本。
    【解决方案3】:

    你可以使用:

    $('li.active a').text("new text here");
    

    如果你想通过href得到它,那么使用属性相等选择器:

    $(a[href="#tabopen_tickets"]).text("new text here");
    

    【讨论】:

      【解决方案4】:

      您可以使用 jquery 选择包含、开头或结尾的一些文本的链接 var link = $('a[href*="#tabopen_tickets"]') 和 然后将链接文本更改为link.innerHTML("new text"); 文档可以在here找到

      【讨论】:

        猜你喜欢
        • 2013-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        • 2012-04-15
        • 2012-05-17
        • 2013-05-01
        • 2012-12-17
        相关资源
        最近更新 更多