[英]disable input box on check box jquery NO onchange
In my project i have a check box that is the basis if the input box is disable. 在我的项目中,我有一个复选框,如果输入框被禁用,它就是基础。 When using the click
event i achieve it correctly but when i get it in database it does not behave correctly but i get the value i am expecting. 当使用click
事件时,我可以正确实现它,但是当我在数据库中获取它时,它的行为不正确,但是我得到了我期望的值。 For example the value is 0
it will display disable false and the disable is false (default) when value is 1
it will display disable true but the input is not disabled here is the code any suggestion is appreciated 例如,值是0
时将显示disable false,disable为false(默认值),当值是1
时将显示disable true,但输入未禁用,这里的代码值得任何建议
On click event 点击事件
$('#flag').click(function() {
console.log("sumenu change on click");
if ($(this).is(":checked")) {
$('#url').prop('disabled', true);
console.log("check disble true");
} else {
$('#url').prop('disabled', false);
console.log("nocheck disble false");
}
});
Code from ajax success that is getting value and should turn off / turn on input on data load 来自ajax成功的代码正在获得价值,应该在加载数据时关闭/打开输入
if (data[i].flag == "0") {
console.log("value is 0 no check disble false");
$('#flag').prop('checked', false);
$('#url').prop('disable', false);
} else {
console.log("value is 1 check disble true");
$('#flag').prop('checked', true);
$('#url').prop('disable', true);
}
There is a syntax error in your code, 您的代码中存在语法错误,
it should be , $('#url').prop('disabled', true);
应该是$('#url').prop('disabled', true);
not, $('#url').prop('disable', true);
不是, $('#url').prop('disable', true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.