Password: Password:

Home  >  Article  >  Web Front-end  >  Methods and techniques for controlling the read-only or writable attributes of a text field using JS

Methods and techniques for controlling the read-only or writable attributes of a text field using JS

怪我咯
怪我咯Original
2018-05-21 11:00:211937browse


The examples in this article describe the JS method of controlling the read-only or writable attributes of a text field. Share it with everyone for your reference, the details are as follows:

<input id="username" name="userneme" type="text" style="width:50px" size=106>
密码:<input id="userpwd" type="text" name="userpwd" size=106 style="width:50px">
<input name="content" type="checkbox")" value="checkbox" onclick="changeCheck()"/>
匿名发表(免注册)
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeCheck()
{
var aa=document.getElementById("username");
var bb=document.getElementById("userpwd");
var cc=document.getElementById("content");
if(cc.checked)
{
aa.readonly=true;
bb.readonly=true;
aa.disabled = true;
bb.disabled = true;
}
else
{
aa.readonly=false;
bb.readonly=false;
aa.disabled = false;
bb.disabled = false;
}
}
//-->
</SCRIPT>

Note: is read-only and unavailable above. If it is generally unavailable, there is no need to read-only. It is ok. Select appropriately
There is no
ONCHANGE event in the HTML CHECKBOX control, only RADIO has it, and CHECKBOX only has the ONCLICK event

The above is the detailed content of Methods and techniques for controlling the read-only or writable attributes of a text field using JS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn