【问题标题】:JQuery select all elements without disabled AND no readonly?JQuery 选择所有没有禁用且没有只读的元素?
【发布时间】:2011-03-03 16:50:43
【问题描述】:

使用 JQuery,我需要选择具有条件的所有 INPUT 元素:

'NOT disabled' (:disabled) 'AND' 'NOT readonly',

然后我将更改 css 样式以查询结果。

更新:我需要按顺序迭代结果..

【问题讨论】:

    标签: jquery


    【解决方案1】:

    详细说明:

    $('input:not(:disabled):not([readonly])').each(function() {
         $(this).foo();
    });
    

    或者更好:

    $('input:enabled:not([readonly])').each(function() {
         $(this).foo();
    });
    

    编辑: 从您的以下答案中,有一种更好的方法可以做您想做的事情:

    $('input').focus(function(e) {
        if($(this).is(':disabled, [readonly]')) {
            $(this).next().focus();
            e.preventDefault();
        }
    });
    

    【讨论】:

      【解决方案2】:

      我真的需要这些:

      $('input:not(input:enabled:not([readonly]))').each(function() {
       //skip focus to readonly input
          $(this).focus(function(){
              $(this).nextAll('input:enabled:not([readonly])')[0].focus();
          });
      });
      

      【讨论】:

      • 你应该看看我更新的答案。有一种更清洁的方法。
      猜你喜欢
      • 1970-01-01
      • 2017-12-11
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      • 2011-01-27
      • 1970-01-01
      • 2016-11-02
      相关资源
      最近更新 更多