可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am working with AST.Net and jQuery 1.8.3.
I want to make a textbox's readonly property to be true on pageload and false when a script runs. My code goes like this:
function showdiv() { $("#diviv").fadeIn("slow"); $("#txtname").attr('readonly', false); $("#txtmobile").attr('readonly', false); $("#txtemail").attr('readonly', false); }
I want to make the readonly property of these three textboxes to be false when the function showdiv
runs. Also I am making a div visible when the script runs. But it's not making it false. Please give me some suggessions how to make it run and tell me where the problem is.
回答1:
Readonly is a boolean attribute, which means that if it is present, no matter what value it has, it will be set. Since attributes are always strings, you are setting it to "false". Use prop instead.
$("#txtname").prop('readonly', false);
回答2:
try this
$("#txtmobile").prop('readonly', false);
OR
$("#<%= txtname.ClientID %>").prop('readonly', false);
回答3:
readonly
is a boolean attribute, which means that if it is present, no matter what value it has, it will be set. Since attributes are always strings, you are setting it to "false"
. Use prop
instead.
$("#txtname").prop('readonly', false);
回答4:
You just can use removeAttr in jquery.
$("#txtmobile").removeAttr('readonly');
回答5:
The readonly
property of a textbox is does not take true/false
as values, all you have to specify is the keyword readonly
like so,
<input type="text" id="txtName" readonly />
Now, to "disable" this property, you will have to remove this using jQuery's .removeAttr()
method,
$("#txtName").removeAttr("readonly");
test link