jQuery的:检查disabled属性和添加/删除呢? [英] jQuery: Checking for disabled attribute and adding/removing it?

查看:208
本文介绍了jQuery的:检查disabled属性和添加/删除呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我选择一个表单的所有输入内容是这样的:

I select all input elements of a form like this:

var fields = $( form + " :input" ).not( "button" );

我如何检查是否有这些投入有禁用属性设置和删除它时,present?

How do I check if any of these inputs has the disabled attribute set and remove it when present?

另外,我需要添加后就是已被删除(以及它们之间的序列字段),是否有这个优雅的方式?类似切换但属性?

Also, I need to add it after is has been removed (and serialize the fields in between), is there an elegant way for this? Something like toggle but for attributes?

推荐答案

假设你正在使用jQuery 1.6或以上,建议的方法是使用的 .prop()

Assuming you are using jQuery 1.6 or above, the suggested method is to use .prop().

fields.prop(已禁用,FALSE);

如果您需要在每一个身边的逻辑,你可以做一些事来的程度。

If you need to have logic around each one, you could do something to the extent of

var fields = $( form + " :input" ).not( "button" );
fields.each(function(index, element) {
    var isDisabled = $(element).is(':disabled');
    if (isDisabled) {
        $(element).prop('disabled', false);
    } else {
        // Handle input is not disabled
    }
});

的jsfiddle

这篇关于jQuery的:检查disabled属性和添加/删除呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆