日期:2014-05-16 浏览次数:20417 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js控制文本框的可否输入</title>
<script type="text/javascript">
function w(){
document.getElementById("text").removeAttribute("readOnly");
document.getElementById("text").style.color="#000000";
document.getElementById("text").style.border="1px solid #3974f8";/*在IE下不可用,IE下为默认的边框颜色,IF可以用哦*/
}
function r(){
document.getElementById("text").setAttribute("readOnly","true");
document.getElementById("text").style.color="#cccccc";
document.getElementById("text").style.border="1px solid #cccccc";
}
</script>
</head>
<body>
<input type="text" id="text">
<input type="button" onclick="javascript:w();" value="可写">
<input type="button" onclick="javascript:r();" value="只读">
</body>
</html>