日期:2014-05-16  浏览次数:20410 次

Dom文本框只读问题?
<html>
<head>
<title> My   JSP   'test2.jsp '   starting   page </title>
</head>
<script   type= "text/javascript ">
function   pageinit()
{
createInput();
}
function   createInput()
{
var   e=document.getElementById( 'tar ');
var   inp=document.createElement( 'input ');
inp.name= 'a ';
inp.type= 'text ';
inp.value= '为什么文本框里的值可以被改变? ';
inp.readonly= 'true ';                                               //关键是这个readonly属性怎么实现
inp.width= '200 ';
e.appendChild(inp);
}
</script>    
<body   onload= "pageinit() ">
<div   id= "tar "> </div>
<div> <input   id= "tar2 "   name= "b "   type= "text "   value= "这里的值不能被改变 "   readonly=true   width= "300 "   /> </div>
</body>
</html>

------解决方案--------------------
大小写问题, inp.readOnly= 'true ';