当前位置: 代码迷 >> JavaScript >> js设立input的readonly不成功
  详细解决方案

js设立input的readonly不成功

热度:43   发布时间:2013-06-19 10:26:41.0
js设置input的readonly不成功
本帖最后由 xtm_rongbing 于 2013-04-25 00:03:19 编辑
function p_edit(id) {
if(document.getElementById("plot_name").readOnly)
{
document.getElementById("plot_name").readOnly = false;
if(!document.getElementById("plot_name").readOnly)
alert("readonly");  
}
else
{
document.getElementById("plot_name").readOnly = true;
if(document.getElementById("plot_name").readOnly)
alert("false");
}
}


<input type="text"  id="plot_name"  name="plot_name1"  value="test" readonly />

js中的alert都可以执行,感觉是设置成功了,可是在界面中,却没有效果,请问这是为什么?求帮助,万分感谢!



------解决方案--------------------
是readonly,注意大小写。
------解决方案--------------------
function p_edit(id) {
if(document.getElementById("plot_name").readOnly)
{
// 你这段红色代码把readonly属性设置为了false了,即不是只读,就可编辑了
document.getElementById("plot_name").readOnly = false;
if(!document.getElementById("plot_name").readOnly)
alert("readonly");  
}
else
{ 
document.getElementById("plot_name").readOnly = true;
if(document.getElementById("plot_name").readOnly)
alert("false");
}
}

  相关解决方案