我在ASP.NET上有这个简单的html按钮,按下按钮我想清除textbox1,专注于textbox1并防止回发。我怎样才能做到这一点?防止回发也会停止按钮清除和聚焦的能力。感谢。
$("#button1").click(function () {
var text1 = $("#textbox1").val();
$.connection.moveshapehub.server.sendmessage1(text1); //send text to hub
//want to clear textbox1 + focus on textbox1
return false; //prevent asp.net postback
});
答案 0 :(得分:3)
$("#button1").click(function (e) {
e.preventDefault();
var text1 = $("#textbox1").val();
$.connection.moveshapehub.server.sendmessage1(text1); //send text to hub
//want to clear textbox1 + focus on textbox1
$("#textbox1").focus().val("");
return false; //prevent asp.net postback
});