当前位置: 代码迷 >> ASP.NET >> 当checkbox替true时,textbox的enable为ture;反之,textbox的enable为false
  详细解决方案

当checkbox替true时,textbox的enable为ture;反之,textbox的enable为false

热度:2826   发布时间:2013-02-25 00:00:00.0
当checkbox为true时,textbox的enable为ture;反之,textbox的enable为false
当checkbox为true时,textbox的enable为ture;反之,textbox的enable为false。
用javascript怎么写?

------解决方案--------------------------------------------------------
<asp:checkbox onclick= "document.getElementById( 'TextBox1 ').disabled=!this.checked " /> <asp:textbox id= "txt1 " />
------解决方案--------------------------------------------------------
1楼的正解!!
<input type= "checkbox " onclick= "document.getElementById( 'txt1 ').disabled=!this.checked " /> <input type= "text " id= "txt1 " />

LZ是不是在txt1这个地方出了问题 ?
你可以直接采用1楼的办法 !!!
------解决方案--------------------------------------------------------
你上面要都用web控件的话 虽然别的地方是方便了
但是 你非要写成JS 方法的话
那就要用AJAX方法了

自己下一个 ajaxpro.2.dll去 然后在工程中添加引用
在web.config中配置
<system.web>
....
<httpHandlers>
<add verb= "POST,GET " path= "ajaxpro/*.ashx " type= "AjaxPro.AjaxHandlerFactory,AjaxPro.2 "/>
</httpHandlers>

然后按我上面的写就行了
------解决方案--------------------------------------------------------
使用javascript就可以实现了!
function check()
{
var ch = document.getElementBy( "checkBox ");
var text = document.getElementBy( "textBox ");
if(ch.Checked)
{
text.enable = true;
}
else
{
text.enable = false;
}
}
------解决方案--------------------------------------------------------
LS的你说使JS就实现了 那我问你 他用的checkbox是web的 那用什么事件调用你的JS 方法呢?
------解决方案--------------------------------------------------------
有onClick?
------解决方案--------------------------------------------------------
<asp:checkbox onclientclick= "document.getElementById( ' <%=txt1.clientid%> ').disabled=!this.checked " runat=server /> <asp:textbox id= "txt1 " runat=server/>



------解决方案--------------------------------------------------------
要我选择的话 我要不就全用HTML控件,要不就全用web控件(刷就刷去)
或者就是选择使用你的这种需求 使用web控件,调用AJAX方法(但是还是感觉用HTML控件调用AJAX方法好点。。。)
------解决方案--------------------------------------------------------
<asp:checkbox onclick= "document.getElementById( ' <%=txt1.clientid%> ').disabled=!this.checked " />

都是服务器端就不能使用 <%=txt1.clientid%> ,改成这样
<asp:checkbox id= "chk1 " run....
<asp:TextBox id= "txt1 " run....


Page_Load
{
this.chk1.Attributes[ "onclick "] = "document.getElementById( ' " + txt1.ClientID + " ').disabled=!this.checke; ";
}

------解决方案--------------------------------------------------------

asp控件的onclick能写脚本?见试了,修改LZ的。
去掉了两个单引号,但是会报服务器空间不能包含 <% %> ,
介意写个funciton 试下
--------------------
liuhui810(小苹果) ( ) 信誉:66 2007-9-21 11:52:03 得分: 0



我的textbox是服务器端控件,所以我这样写的:
<asp:checkbox onclick= "document.getElementById( <%=txt1.clientid%> ).disabled=!this.checked " /> <asp:textbox id= "txt1 " />

可却报错:document.getElementById(...)为空或不是对象





------解决方案--------------------------------------------------------
<asp:TextBox ID= "TextBox1 " runat= "server " </asp:TextBox>
<input type= "checkbox " id= "Checkbox1 " onclick= "document.getElementById( 'TextBox1 ').disabled=this.checked "/> </div>
  相关解决方案