struts2.0中 如何动态控制readonly 属性

zhen_beginner 2010-04-30 06:09:32
<table align="center" width="60%"
style="color: #369; border: #92B0DD 1px solid; margin-top: 30px;"
id="tab">
<tr>
<td colspan="2" align="center"><%=request.getParameter("host")%><%=request.getParameter("zone")%></td>
</tr>
<tr>
<td class="bo_01">
在线设置:
</td>
<td class="bo_01">
<table id=OnlineOpt style="FONT-SIZE: 9pt" border=0>
<tbody>
<tr>
<td>
<input id="OnlineOpt_0" type="radio" checked value="0"
name="OnlineOpt" />

<label for="OnlineOpt_0">
解析到最新的IP上
</label>
</td>
<td>
<input id="OnlineOpt_1" type="radio" value="1"
name="OnlineOpt" />
<label for="OnlineOpt_1">
指定到静态IP上
</label>
</td>
<td>
<input id="OnlineOpt_2" type="radio" value="2"
name="OnlineOpt" />
<label for="OnlineOpt_2">
转发指定的网址
</label>
</td>
</tr>
</tbody>
</table>
  静态IP:

<s:textfield id="OnlineIP" name="domain.data" readonly="true" ></s:textfield>
<br />
指定网址:
<s:textfield id="OnlineUrl" name="domain.data" readonly="true"></s:textfield>
</td>
</tr></table>
<script>

document.getElementById("OnlineOpt_0").onclick=function()
{
document.getElementById("OnlineIP").readonly=true;
document.getElementById("OnlineUrl").readonly=true;

}
document.getElementById("OnlineOpt_1").onclick=function()
{

document.getElementById("OnlineIP").readonly="false";
document.getElementById("OnlineIP").focus();
document.getElementById("OnlineUrl").readonly="true";

}
document.getElementById("OnlineOpt_2").onclick=function()
{
document.getElementById("OnlineIP").readonly=true;
document.getElementById("OnlineUrl").readonly=false;
document.getElementById("OnlineUrl").focus();

}
</script>
...全文
1902 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wpstock 2012-07-13
  • 打赏
  • 举报
回复
刚才看到
顺便给你解决

$("#id").attr("readonly",true);
$("#id").attr("readonly",false);

true 和 false 都不要加 “” 就可以了! 如果加 “” 了 只有true 会起效,false 是不会起效,这就导致你现在的效果!

zhen_beginner 2010-05-04
  • 打赏
  • 举报
回复
谢谢!
不学-何为 2010-05-01
  • 打赏
  • 举报
回复
Name Required Default Evaluated Type Description
readonly false false false Boolean Whether the input is readonly
teemai 2010-05-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhen_beginner 的回复:]
点击单选按钮,对应的文本框变为可写。struts2.0 中readonly只有一次有效吗?怎么解决这个问题?
[/Quote]

<script>

document.getElementById("OnlineOpt_0").onclick=function()
{
document.getElementById("OnlineIP").readonly=true;
document.getElementById("OnlineUrl").readonly=true;

}
document.getElementById("OnlineOpt_1").onclick=function()
{

document.getElementById("OnlineIP").readonly="false";
document.getElementById("OnlineIP").focus();
document.getElementById("OnlineUrl").readonly="true";

}
document.getElementById("OnlineOpt_2").onclick=function()
{
document.getElementById("OnlineIP").readonly=true;
document.getElementById("OnlineUrl").readonly=false;
document.getElementById("OnlineUrl").focus();

}
</script>

执行之前进行判断啊,举个类子:
document.getElementById("OnlineOpt_0").onclick=function()
{
if(document.getElementById("OnlineIP").readonly==false){
document.getElementById("OnlineIP").readonly=true;
document.getElementById("OnlineUrl").readonly=true;
}else if(document.getElementById("OnlineIP").readonly==true){
document.getElementById("OnlineIP").readonly=false;
document.getElementById("OnlineUrl").readonly=false;
}

}
zhen_beginner 2010-04-30
  • 打赏
  • 举报
回复
点击单选按钮,对应的文本框变为可写。struts2.0 中readonly只有一次有效吗?怎么解决这个问题?

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧