首页 新闻 搜索 专区 学院

asp.net 按下键盘Backspace触发事件,求教

0
[已关闭问题] 关闭于 2013-03-29 16:40

                                                                                                                                                            

丶夏之星的主页 丶夏之星 | 初学一级 | 园豆:5
提问于:2013-03-25 20:03
< >
分享
所有回答(3)
0

<script language="javascript" type="text/javascript" src="jquery-1.7.2.js"></script>

 <form id="form1" runat="server">
        <script language="c#" runat="server">
            protected void Button1_Click(object sender, EventArgs e)
            {
                TextBox1.Text = "Backspace1111111触发事件";
            }
            protected void Button2_Click(object sender, EventArgs e)
            {
                TextBox1.Text = "Backspace2222222触发事件";
            }
        </script>

        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" Style="display: none" OnClick="Button1_Click" />
            <asp:Button ID="Button2" runat="server" Text="Button" Style="display: none" OnClick="Button2_Click" />
        </div>

        <script language="javascript" type="text/javascript">
         $("#TextBox1").keyup(function (event) { 
            var keycode = event.which; 
            if(keycode==8){
                $("#Button1").click();
            }
            else if(keycode==8){
                alert("回车键");
            }
            else{
                $("#TextBox1").val("不是Backspace键");
            }
        });
       
        $(document).keyup(function(event){  
             //获取当前按键的键值   
             //jQuery的event对象上有一个which的属性可以获得键盘按键的键值   
             var keycode = event.which;  
             //处理回车的情况   
             if(keycode==13){  
                  alert("回车键111");
            }  
             //处理esc的情况   
             if(keycode == 27){  
                 alert("esc111");
             }
             if(keycode==8){
                $("#Button2").click();
            }
         });
        </script>
    </form>

q_po_o | 园豆:202 (菜鸟二级) | 2013-03-25 22:23
0

直接后台keypress事件keyCode属性判断

问心、 | 园豆:94 (初学一级) | 2013-03-26 09:57
0

Backspace是浏览器用作回退的快捷键,建议保留。

Luke Zhang | 园豆:293 (菜鸟二级) | 2013-03-26 17:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册