【问题标题】:How select an element button by title and hide it?如何按标题选择元素按钮并将其隐藏?
【发布时间】:2016-10-29 10:52:54
【问题描述】:

我在页面上有以下按钮,我想要的只是能够通过标题或任何其他属性选择它并将其隐藏。

<button title="Show all journal fields" type="button" class="icon-stream-all-input btn-default btn" ng-click="toggleMultipleInputs(true)"> <span class="sr-only"> Show all journal fields </span></button>

【问题讨论】:

  • 那么去查找 CSS 属性选择器。
  • $("button [title='Show all journal fields']").hide();

标签: javascript jquery html angularjs


【解决方案1】:

你可以为title属性使用属性选择器:

var titleSearchStr = 'Show all journal fields';
var items = $('[title="'+ titleSearchStr +'"]');
items.hide();

【讨论】:

    【解决方案2】:

    CSS 方法

    button[title="Show all journal fields"]{
    display:none;
    }
    &lt;button title="Show all journal fields" type="button" class="icon-stream-all-input btn-default btn" ng-click="toggleMultipleInputs(true)"&gt; &lt;span class="sr-only"&gt; Show all journal fields &lt;/span&gt;&lt;/button&gt;

    Javascript 方法

    document.querySelector("button[title='Show all journal fields']").style.display="none";
    &lt;button title="Show all journal fields" type="button" class="icon-stream-all-input btn-default btn" ng-click="toggleMultipleInputs(true)"&gt; &lt;span class="sr-only"&gt; Show all journal fields &lt;/span&gt;&lt;/button&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 2011-06-30
      • 2018-03-20
      相关资源
      最近更新 更多