在jQuery中提交禁用的表单域的最佳方法? [英] Best method for submitting disabled form fields in jQuery?
问题描述
- 在jQuery中提交(POST)禁用的表单字段似乎有几种方法:输入更改并提交
- 在提交时手动附加键/值对
- 在服务器端还原值(仅当值不是预期的时候以改变)
- 在提交时手动附加键/值对
我想知道哪些(如果有)被认为是提交禁用表单域的最佳做法。很明显, readOnly
在可用时是最好的选择,但我有复选框,即使它们被禁用(由于业务逻辑)也需要提交。我意识到这不是一个理想的情况,但很少是web开发中的情况。
是否有提交禁用表单元素的最佳做法? 解决方案
p>最好的选择是使输入只读 - 为复选框创建一个简单的事件,返回false,并更改它们的背景颜色。
没有最好的练习,但那需要最少的欺骗。
There seem to be several ways to submit (POST) disabled form fields in jQuery:
- Have a hidden field that changes when the input changes, and submit that
- Manually append the key/value pairs upon submission
- Revert values on the server-side (only if values not expected to change)
I was wondering which (if any) is considered best practice for submitting disabled form fields. Obviously readOnly
is the best option when it's available, but I have checkboxes that I need to submit even though they are disabled (due to business logic). I realize this is not an ideal situation, but rarely is that the case in web development.
Is there a best-practice for submitting disabled form elements?
The best option is to make the inputs readonly - create a click event for the check boxes that simply returns false, and change their background color.
There is no best practice, but that one requires the least fudging.
这篇关于在jQuery中提交禁用的表单域的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!