【问题标题】:How to select checkboxes with opacity:0.5如何选择不透明度的复选框:0.5
【发布时间】:2012-07-06 19:33:58
【问题描述】:

如何选择带有opacity: 0.5 的复选框?

选择器:checkbox[style~='opacity: 0.5'] 不会选择它们。

【问题讨论】:

    标签: jquery css jquery-selectors dom-traversal


    【解决方案1】:

    filter() 方法允许您编写一个函数,该函数将对所有元素运行,并且仅当函数返回 true 时才会将它们包含在结果集中。

    $('input[type="checkbox"]').filter(function () {
        return $(this).css('opacity') == 0.5;
    }).addClass('marked');​
    

    这将在每个不透明度为 0.5 的元素上添加一个“标记”类。

    注意:您应该 use classes 而不是直接从 Javascript 操作和查询 CSS。

    【讨论】:

    • 好的。非常感谢,bažmegakapa
    【解决方案2】:

    试试这个:

    $('input').filter(function() {
         return $(this).css('opacity') == '0.5';
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多