Javascript 控制disabled属性

hhh871030 2009-11-03 10:41:58

<script language="javascript" type="text/javascript">
function Check()
{
var a=document.getElementById("txtIsAwardContract" );
if(a.value=="是")
document.getElementById('txtRevisionFee').disabled=true;
}

</script>

<asp:TextBox ID="txtIsAwardContract" runat="server"></asp:TextBox>
<asp:TextBox ID="txtRevisionFee" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClientClick="Check()" Text="测试" />

代码是在文本框里输入“是”的时候,后面一个文本框就不可用。可是怎么都实现不了。问题是。当我把最后一段代码document.getElementById('txtRevisionFee').disabled=true;中的'txtRevisionFee'改成'Button1'就可以实现按钮不可用了。
...全文
537 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhh871030 2009-11-03
  • 打赏
  • 举报
回复
呵呵。。问题解决了。。。OnClientClick中要写成return Check()。。感谢各位的帮助
街头小贩 2009-11-03
  • 打赏
  • 举报
回复
ie 7. output:true
街头小贩 2009-11-03
  • 打赏
  • 举报
回复

function Check()
{
var a=document.getElementById('a' );
if(a.value=="是"){
document.f.b.disabled=true;
alert(document.getElementById('b').getAttribute('disabled'));
}
}

</script>

opera 10. output:true
ie 8. output:DISABLED
ff 3.5 output: 空
ie6.
sorry!我的MultipleIEs好象出了点问题ie6测不出来
街头小贩 2009-11-03
  • 打赏
  • 举报
回复
哈哈!我上面的也点问题!disabled="disabled"才能通过w3c的validate
sohighthesky 2009-11-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xiaofanku 的回复:]
引用 2 楼 sohighthesky 的回复:


文件 本框 没有不可用状态



谁告诉你的!试试
[/Quote]

lz告诉我的
街头小贩 2009-11-03
  • 打赏
  • 举报
回复
http://www.w3.org/TR/html401/interact/forms.html#adef-disabled
The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.
街头小贩 2009-11-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sohighthesky 的回复:]



文件 本框 没有不可用状态


[/Quote]
谁告诉你的!试试

<!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>无标题文档</title>
<script language="javascript" type="text/javascript">
function Check()
{
var a=document.getElementById('a' );
if(a.value=="是") document.getElementById('b').disabled=true;
}

</script>

</head>

<body>
<input type="text" id="a" disabled="true" name="a" />
<input type="text" id="b" name="b" />
<input type="button" onclick="Check()" value="click" />
</body>
</html>
sohighthesky 2009-11-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 hhh871030 的回复:]
一段代码document.getElementById('txtRevisionFee').disabled=true;中的'txtRevisionFee'改成'Button1'就可以实现按钮不可用了。

[/Quote]
文件 本框 没有不可用状态
document.getElementById('txtRevisionFee').readOnly="readOnly";
  • 打赏
  • 举报
回复
不会用asp。又没有编译生成之后的html页面发一个看看

87,915

社区成员

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

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