【问题标题】:change first attribute only while there are 2 having the same name in JQuery仅在 JQuery 中有 2 个同名时更改第一个属性
【发布时间】:2020-01-27 04:31:02
【问题描述】:

所以我到处搜索我找不到答案

thisObj.$playpauseButton.find('svg').attr('viewBox',newSvgData[0]);

<svg focusable="false" aria-hidden="true" viewBox="-40 -130 500 600" viewbox="-28 -140 500 600">

这里的代码只改变了最后一个 viewbox 属性,而不是两者, 如何同时选择或只选择第一个?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    你也可以使用 jQuery eq

    现在,您的脚本应该如下所示

    $('.able-button-handler-play').find('svg').eq(0).setAttribute('viewBox','-28 -140 500 600');
    

    【讨论】:

      【解决方案2】:

      我找到了使用 setAttribute() 的解决方法,因为它区分大小写。

      As in here

      $('.able-button-handler-play').find('svg')[0].setAttribute('viewBox','-28 -140 500 600');
      

      【讨论】:

        猜你喜欢
        • 2015-09-06
        • 2021-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-24
        • 2018-01-28
        • 1970-01-01
        • 2020-02-21
        相关资源
        最近更新 更多