html disabled 和readonly,disabled 引起的form表单提交问题

本文探讨了HTML表单中readonly与disabled属性的区别,包括它们如何影响用户交互及表单提交行为。disabled不仅禁止用户更改字段值,还使得这些字段在表单提交时不被发送。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



先看看这两个属性在效果和使用上的区别

READONLY and DISABLED both remove the functionality of the input field, but to different degrees. READONLY locks the field: the user cannot change the value. DISABLED does the same thing but takes it further: the user cannot use the field in any way, not to highlight the text for copying, not to select the checkbox, not to submit the form. In fact, a disabled field is not even sent if the form is submitted.


对于diabled掉的form 表单,

<form id="product_form">
<fieldset id="static_fields" disabled="disabled">
<div class="form-group">
<label class="col-lg-2 control-label" for="product_name">产品名称</label>
<div class="input-group col-lg-6 ">
<input class="form-control static" id="product_name" name="projectName" title="" data-toggle="tooltip" data-placement="bottom" data-original-title="产品名称">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="capital">募集金额</label>
<div class="input-group col-lg-6 ">
<span class="input-group-addon"><i class="fa">¥</i></span>
<input type="number" min="1" max="100000000" class="form-control static" id="capital" title="" name="capital" data-toggle="tooltip" data-placement="bottom" data-original-title="募集金额">
<span class="input-group-addon"><span>.00</span></span>
</div>
</div>

</fieldset>

</form>

1,我们会发现 input 里的value 在调试时候不能像原来那样查看,必须去prpperties中去查看


2,用js 获取表单内容,会获取到空值,input的值也不会被传到服务器

var form = $('#product_form').serialize();
$.post(url, form, function(data) {
if (data && data.code) {
if (data.code == 0) {
console.log('goto product info page.');
// 刷新页面
alert('修改成功');
} else {
alert(data.message + "[" + data.code + "]");
}
} else {
alert("内部错误");
}
});

调试会发现 form="projectID=&projectName=&capital=" 类似的空值,

所以,我们必须在用js提交表单时候,主动将diabled属性去掉  $('#static_fields').removeAttr("disabled");


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值