使用javascript在asp.net中启用了文本框 [英] enabled textbox in asp.net with javascript

查看:51
本文介绍了使用javascript在asp.net中启用了文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP中将我的三个文本框设置为enabled = false,我想更改它们的enabled = true
当我的三个单选按钮之一选中时,但不起作用


I set my three textbox enabled=false in asp and I want to change their enabled = true
when one of my three radio button checked.but it does not work


<head  runat="server">
<script language="javascript" type="text/javascript">


 function Radio1_onclick() {

            document.getElementById('TextBox1').Enabled = true;
        }

 function Radio2_onclick() {
            document.getElementById('TextBox2').Enabled = true;
        }

 function Radio3_onclick() {
            document.getElementById('TextBox1').Enabled = true;
            document.getElementById('TextBox2').Enabled = true;
        }

</script>

</head>





<body>
    <form id="form1" runat="server">
<div>

<table>

<tr>
  <td class="style1">  
     <asp:Label ID="Label1" runat="server" Text="شماره dsl :">    <asp:TextBox ID="TextBox1"  runat="server" Enabled="False"></td>
  <td class="style2"> 
<asp:Label ID="Label2" runat="server" Text="کد کاربری :"> <asp:TextBox ID="TextBox2" runat="server" Enabled="False"></td>
               
 </tr>


<tr>
<td> <asp:Label ID="Label3" runat="server" Text="DSL :">
            
<input id="Radio1" type="radio" value="rd1" name="val"   önclick="return Radio1_onclick()" /></td>
            
<td> <asp:Label ID="Label4" runat="server" Text="کد کاربری :"> 
            
<input id="Radio2" type="radio" value="rd2" name="val"   önclick="return Radio2_onclick()" /></td>
            
<td> <asp:Label ID="Label5" runat="server" Text="هر دو"> 
            
<input id="Radio3" type="radio" value="rd3" name="val"   önclick="return Radio3_onclick()" /></td>
            </tr>

</table>

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

推荐答案

尝试使用此代码:


try use this code:


<script language="javascript" type="text/javascript">

 function Radio1_onclick() {                                                                                
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
        }
 function Radio2_onclick() {
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
        }
 function Radio3_onclick() {
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
        }                                                                                           
</script>




或此代码:





or this code:


<script language="javascript" type="text/javascript">

function Radio_onclick() {
if(document.getElementById('Radio1').checked){
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
        }
else if(document.getElementById('Radio2').checked){
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
        }
else if(document.getElementById('Radio3').checked){
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
}                                                                                                             

</script>




调用Radio_onclick函数的所有单选按钮onclick事件.




call Radio_onclick function all radio button onclick event.


我想您有第三个文本框为"TextBox3",并且如果选中了任何单选按钮,则希望启用所有三个文本框.

编写一个常见的Javascript函数"EnableTextboxes()",并在单选按钮的onClick事件上调用它.

I guess you have Third text box as "TextBox3" and you want to enable all three textboxes if any radio button is checked.

Write one common Javascript function "EnableTextboxes()" and call it on onClick event of your Radio Buttons.

function EnableTextboxes() 
{
 if(document.getElementById(''<%= Radio1 %>'').checked || document.getElementById(''<%= Radio2 %>'').checked ||
document.getElementById(''<%= Radio3 %>'').checked)
{
 document.getElementById(''<%= TextBox1.ClientID %>'').disabled = false;
  document.getElementById(''<%= TextBox2.ClientID %>'').disabled = false;
document.getElementById(''<%= TextBox3.ClientID %>'').disabled = false;
|

}

<input id="Radio1" type="radio" value="rd1" name="val"   önclick="return EnableTextboxes()" />
                      
<input id="Radio2" type="radio" value="rd2" name="val"   önclick="return EnableTextboxes()" />
                       
<input id="Radio3" type="radio" value="rd3" name="val"   önclick="return EnableTextboxes()" />


这篇关于使用javascript在asp.net中启用了文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆