首页 新闻 赞助 找找看

TextBox的TextChanged事件中js focus不起作用

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-08-17 23:10

代码:
<form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div>
                    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                    <asp:TextBox ID="TextBox2" runat="server" TabIndex="9"></asp:TextBox>
                    <asp:TextBox ID="TextBox3" runat="server" TabIndex="10"></asp:TextBox>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
后台:
protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        TextBox2.Text = DateTime.Now.ToString();
        ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, this.GetType(), "show1","document.getElementById('TextBox3').focus();", true);
    }
这样写TextBox1输入内容改变后,焦点到不了TextBox3,但是在document.getElementById('TextBox3').focus();加个alert('1');又可以。在网上查到focus方法延迟触发,放在setTimeout中也不行;就是setTimeout(function() {document.getElementById('TextBox3').focus();},200); 同样在前面加个alert又可以

999999999999999的主页 999999999999999 | 初学一级 | 园豆:3
提问于:2014-08-06 22:05
< >
分享
所有回答(3)
0

事件的触发机制是失去焦点之后触发的,而不是在按键点击前后发生。

lucika.zh | 园豆:62 (初学一级) | 2014-08-07 08:53
0

你想实现什么效果,直接说问题吧!

晓菜鸟 | 园豆:2594 (老鸟四级) | 2014-08-07 10:18

就是  TextBox1 触发服务端事件 TextChanged, TextBox3得到焦点

支持(0) 反对(0) 999999999999999 | 园豆:3 (初学一级) | 2014-08-07 21:23

@999999999999999: TextBox1 的文本内容改变后,你点击一下空白处会触发吗?

支持(0) 反对(0) 晓菜鸟 | 园豆:2594 (老鸟四级) | 2014-08-08 10:26
0

设置UpdatePanel的UpdateMode="Always"试试呢

jello chen | 园豆:7306 (大侠五级) | 2014-08-10 14:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册