<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>
直接后台keypress事件keyCode属性判断
Backspace是浏览器用作回退的快捷键,建议保留。