首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

让一个text从readonly状态恢复的有关问题,100分

2012-03-28 
让一个text从readonly状态恢复的问题,100分在线等%@pagelanguage java import java.util.* pageEnc

让一个text从readonly状态恢复的问题,100分在线等
<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "gb2312 "   %>
<html>
<head>
</head>
<script   language= "javascript ">
function   changetype()
{

if(document.forms[0].type[1].checked)
{
document.forms[0].belongto.enabled= "true ";
document.forms[0].projectname.readOnly= "true ";
}
if(document.forms[0].type[0].checked)
{
document.forms[0].belongto.disabled= "true ";
document.forms[0].projectname.readOnly= "false ";
}
}

function   init()
{
if(document.forms[0].type[1].checked)
{


document.forms[0].belongto.enabled= "true ";
document.forms[0].projectname.readOnly= "true ";
}
}
</script>
<body   bgcolor= "#66FF99 "   onload= "init() ">
<h1> 文件上传 </h1>
<form   name= "uploadform "   method= "POST "   action= "/SoftwareReuseLibrary/FileUpload "   ENCTYPE= "multipart/form-data ">
                <table   border= "1 "     cellpadding= "4 "   width= "800 "   cellspacing= "2 "   bordercolor= "#9BD7FF "   align= "center ">
<tr>
<td>
<input   type   = "radio "   name= "type "     value= "new "   onclick= "changetype() "> 新项目上传 </input>
<input   type   = "radio "   name= "type "     value= "update "   checked   onclick= "changetype() "> 更新已有项目 </input>
  </td>
</tr>
<tr>
<td> 新项目名称: <input   type= "text "   name= "projectname "/> </td>
</tr>
<tr>
<td>
请选择上传文件所属的项目:
<select   name= "belongto ">
<option   value= "null "   selected= "selected "> ---------- </option>
<option   value= "1 "> 111111 </option>
</select>
</td>
</tr>

                <tr> <td   colspan= "2 ">
                                              请选择你需要上传的文件: <input   name= "x "   size= "40 "   type= "file "/>
                </td>
</tr>

<tr>
<td>
文件功能描述: <br>
<textarea   name= "fd "   cols= "50 "   rows= "20 "> </textarea>
</td> </tr>

<tr> <td>
作者: <input   type= "text "   name= "author "/> </td> </tr>
                <tr> <td   align= "center "> <input   name= "upload "   type= "submit "   value= "开始上传 "/> </td> </tr>
              </table>


</form>
</body>
</html>


我一开始让用radio单选框来改变projectname(text类型)和belongto(select类型   )的可编辑和不可编辑,可是按了之后却不能从不可编辑状态恢复过来。。。郁闷

[解决办法]
reload的时候使用get提交,而不用post,在提交的时候也不使用document.location.reload(),
而是直接写document.location.href= " "在多加个参数,这样判断是否接收到这个参数来确认是否是刷新还是第一次进入该网页,来区分readOnly
[解决办法]
function changetype()
{
var a = document.uploadform.belongto;
a.disabled = a.disabled == true ? false : true;
}
[解决办法]
<script language= "javascript ">
function changetype()
{
if(document.forms[0].type[1].checked)
{
document.forms[0].belongto.disabled=false;
document.forms[0].projectname.disabled=true;
}else
{
document.forms[0].belongto.disabled=true;
document.forms[0].projectname.disabled=false;
}
}

function init()
{
if(document.forms[0].type[1].checked)
{
document.forms[0].belongto.disabled=false;
document.forms[0].projectname.disabled=true;
}
}
</script>
[解决办法]
这样改就好了

注:1.切换的时候要用true和false不要加引号,要求是Boolean 类型;
2.select没有readonly,只有disabled,另外disabled=true的对象,在提交表单的时候不会提上去。

<html>
<head>
</head>
<script language= "javascript ">
function changetype()
{

if(document.forms[0].type[1].checked)
{
document.forms[0].belongto.disabled=false;
document.forms[0].projectname.readOnly=true;
}
if(document.forms[0].type[0].checked)
{
document.forms[0].belongto.disabled=true;
document.forms[0].projectname.readOnly=false;
}
}

function init()
{
if(document.forms[0].type[1].checked)
{


document.forms[0].belongto.enabled= "true ";
document.forms[0].projectname.readOnly= "true ";
}
}
</script>
<body bgcolor= "#66FF99 " onload= "init() ">
<h1> 文件上传 </h1>
<form name= "uploadform " method= "POST " action= "/SoftwareReuseLibrary/FileUpload " ENCTYPE= "multipart/form-data ">
<table border= "1 " cellpadding= "4 " width= "800 " cellspacing= "2 " bordercolor= "#9BD7FF " align= "center ">
<tr>
<td>
<input type = "radio " name= "type " value= "new " onclick= "changetype() "> 新项目上传 </input>
<input type = "radio " name= "type " value= "update " checked onclick= "changetype() "> 更新已有项目 </input>
</td>
</tr>
<tr>
<td> 新项目名称: <input type= "text " name= "projectname "/> </td>
</tr>
<tr>
<td>
请选择上传文件所属的项目:
<select name= "belongto ">
<option value= "null " selected= "selected "> ---------- </option>
<option value= "1 "> 111111 </option>
</select>
</td>
</tr>

<tr> <td colspan= "2 ">
请选择你需要上传的文件: <input name= "x " size= "40 " type= "file "/>


</td>
</tr>

<tr>
<td>
文件功能描述: <br/>
<textarea name= "fd " cols= "50 " rows= "20 "> </textarea>
</td> </tr>

<tr> <td>
作者: <input type= "text " name= "author "/> </td> </tr>
<tr> <td align= "center "> <input name= "upload " type= "submit " value= "开始上传 "/> </td> </tr>
</table>
</form>
</body>
</html>
[解决办法]
document.forms[0].projectname.readOnly=true; //别用字符串型,用boolean型
document.forms[0].projectname.readOnly=false;

热点排行