2013-06-25 37 views
0

我想启用所有禁用输入和submiting形式,所以我可以得到所有禁用的元素值之前选择元素。启用所有禁用输入和选择元素

所以我试图

function enable() { 

     $('input[type="text"], input[type="checkbox"], select').prop("disabled", true).each(function() { 

      if ($(this).is(':disabled')) { 
       $(this).attr('disabled', false); 
      } 

     }); 
    } 

此代码不能正常工作,所以你可以帮我这个工作。

在此先感谢....

+0

'$( '输入[类型= “文本”],输入[类型= “复选框”],选择')。removeProp(”禁用')' – adeneo

+0

不,它不工作。 –

回答

3

试试这个,

function enable() { 
    $('input[type="text"], input[type="checkbox"], select').each(function() { 
     if ($(this).prop('disabled')) { 
      $(this).prop('disabled',false); 
     } 
    }); 
} 

或者,您也可以使不使用each()像所有禁用的元素,

$('input[type="text"]:disabled, input[type="checkbox"]:disabled, select:disabled') 
      .prop('disabled',false); 

或者使用removeAttr()一样,

$('input[type="text"]:disabled, input[type="checkbox"]:disabled, select:disabled') 
      .removeAttr('disabled'); 
2
$(this).removeAttr('disabled'); 
0

使用道具不ATTR,该.prop()方法提供了一种明确检索属性值,同时.attr()检索属性。

$(this).prop('disabled',false);