[英]Disable text input change but take it with its value in jQuery
I am filling textbox elements with some data come from database. 我用一些来自数据库的数据填充文本框元素。 I am using the same form for different roles.
我为不同的角色使用相同的表格。 Some roles can update these values but others cannot.
一些角色可以更新这些值,而其他角色则不能。 So, I want to disable them for edit.
因此,我想禁用它们进行编辑。
I both used: 我都用过:
$("input:eq(1)").attr("disabled", true);
and 和
$("input:eq(2)").prop('disabled', true);
It works seemingly but when I try to update the form, these values are stored null in database. 它似乎正常工作,但是当我尝试更新表单时,这些值在数据库中存储为空。 At first it fetches and fills the textboxes disabled, but when I click update button, the values are sent to DB as null.
最初,它获取并填充禁用的文本框,但是当我单击“更新”按钮时,这些值将作为空发送到DB。 How can I avoid that problem and provide a solution to push unchanged (because you cannot change) input values into DB?
如何避免该问题并提供解决方案以将不变的(因为您无法更改)输入值推入数据库?
The issue with disabled inputs is that they don't get passed to the database on a submit
post. 输入被禁用的问题在于它们不会在
submit
帖子中传递到数据库。 Try changing them to this: 尝试将它们更改为此:
$("input:eq(1)").attr("readonly", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.