【问题标题】:Remove readonly attribute from all input box using jquery?使用jquery从所有输入框中删除只读属性?
【发布时间】:2016-03-29 06:19:34
【问题描述】:

我有多个输入文本框,默认情况下都是只读的。

我想删除表单中所有输入元素的只读属性,而不是特定元素,我不知道如何使用 jQuery 选择所有输入并删除只读属性(如果已添加)。

HTML:

<input type="text" name="fistname" readonly="true">
<input type="text" name="lastname" readonly="true">
<input type="text" name="emailaddres" readonly="true">
<input type="text" name="password" readonly="true">
<input type="button" name="edit" id="edit">

jQuery :

$(document).ready(function(e){
    $(document).on("click","#edit",function(e){
         // What should i do here..?
    });
});

【问题讨论】:

标签: php jquery


【解决方案1】:

你应该使用prop()来设置属性

$(':input').prop('readonly', false)

OR,使用removeAttr() 方法

$(':input').removeAttr('readonly')

参考文献

【讨论】:

    【解决方案2】:
    $('input.canEdit').attr('readonly', false);
    

    并向您希望允许用户编辑的所有输入元素添加一个类;

    【讨论】:

      【解决方案3】:

      使用removeAttr() 方法,如下所示。

      $(document).on("click","#edit",function(e){
          $('input[type=text]').removeAttr('readonly');
      
          //$(':input').removeAttr('readonly'); //if want to select all types of form controls
      });
      

      【讨论】:

        【解决方案4】:
        $('#edit').click(function (){
           $('input[type=text]').removeAttr('readonly');
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-08-20
          • 1970-01-01
          • 2011-01-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多