我如何添加只读到特定的<输入>?.attr('readonly')不起作用。
当前回答
jQuery < 1.9
$('#inputId').attr('readonly', true);
jQuery 1 + 9。
$('#inputId').prop('readonly', true);
阅读更多关于prop和attr的区别
其他回答
使用$ .prop ()
$("#descrip").prop("readonly",true);
$("#descrip").prop("readonly",false);
我认为“disabled”排除了POST上发送的输入
对于jQuery版本< 1.9:
$('#inputId').attr('disabled', true);
对于jQuery版本>= 1.9:
$('#inputId').prop('disabled', true);
检查下面的代码:
<input id="mail">
<script>
document.getElementById('mail').readOnly = true; // makes input readonline
document.getElementById('mail').readOnly = false; // makes input writeable again
</script>
启用只读功能:
$("#descrip").attr("readonly","true");
禁用只读
$("#descrip").attr("readonly","");