单击复选框必须将光标放在文本框中 [英] Check box clicked must place cursor in textbox

查看:84
本文介绍了单击复选框必须将光标放在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

正在使用Asp.net c#Sqlsever2005.

我有一个包含复选框和文本框的网页.

首次加载页面时,将禁用这些文本框.并且,当用户选中该复选框时,光标必须放在TEXTBOX中.

请帮我.并在此举一个例子


感谢ever

Dear Friends,

am working on Asp.net c# Sqlsever 2005.

I have a web page which consists of Checkbox and Textboxes.

When the first time page loads these textboxes are disabled. AND when user checks the checkbox the cursor must be placed in TEXTBOX.

Please help me. and give me one example on this


Thanks for ever

推荐答案

您可以在JavaScript中使用focus()方法.
这是示例代码.

You can use the focus() method in JavaScript.
Here is a sample code.

<script type="text/javascript">
   function setFocus()
    {
        var checkbox = document.getElementById('<%=checkBox1.ClientID %>');
        var Textbox =  document.getElementById('<%= txtTest.ClientID%>');
        if(checkbox.checked)
        {
          Textbox.disabled =false;
          Textbox.focus();
        }
        else
        {
            Textbox.disabled =true;
        }
    }
    </script>





<asp:CheckBox ID="checkBox1" runat="server" OnCheckedChanged="checkBox1_CheckedChanged"  />
  <asp:TextBox ID="txtTest" runat="server" Enabled="false"></asp:TextBox>




在文件后面的代码中,将此行包含在Page_Load()




In your code behind file include this line under Page_Load()

checkBox1.Attributes.Add("onClick", "setFocus()");


签出此人:
http://msdn.microsoft.com/en-us/library/ms178232%28v = vs.100%29.aspx [ ^ ]
checkout this man:
http://msdn.microsoft.com/en-us/library/ms178232%28v=vs.100%29.aspx[^]


这篇关于单击复选框必须将光标放在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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