HTML只读属性不可移动

html readonly attribute not removable

本文关键字:可移动 只读属性 HTML      更新时间:2023-09-26

我想从以下输入字段中删除readonly属性:

<input id="cno" name="cno" type="number" class="form-control" readonly />
<button type="button" id="no-edit" class="btn btn-warning">Edit</button>

我已经尝试使用jQuery(1.11)来删除单击按钮时的属性。

$("#no-edit").click(function() {
   $("#cno").removeProp('readonly');
});

我也试过使用:

 $("#no-edit").click(function() {
   $("#cno").removeAttr('readonly');
});

请帮忙!我不明白为什么会失败

试试这个:

$("#no-edit").click(function() {
   $("#cno").prop('readonly', false);
});
演示

在文档中换行。

$(document).ready(function () {
        $("#no-edit").click(function() {
           $("#cno").removeAttr('readonly');
       });
})