ASP.NET中把Button的Accesskey设成回车键


设置按钮的UseSubmitBehavior属性为True
服务器解析后的html就为submit按钮

如果是ImageButton的话就用javascript控制了

//定义设置默认按钮函数
public static void SetDefEnterControl(System.Web.UI.Control Ctrl)
{
Page mPage = Ctrl.Page;
string mScript;
mScript = @"<script language=""javascript""> ";
mScript += "function document.onkeydown() {";
mScript += "var e = event.srcElement; ";
mScript += "var k = event.keyCode; ";
mScript += @"if (k == 13 && e.type != ""textarea"") { ";
mScript += "document.all." + Ctrl.ClientID + ".click(); ";
mScript += "event.cancelBubble = true; ";
mScript += "event.returnValue = false; ";
mScript += "} }</script>";

if (mPage.IsClientScriptBlockRegistered("SetEnterControl") == false)
mPage.RegisterClientScriptBlock("SetEnterControl", mScript);


}


//在pageload()事件中在设置

SetDefEnterControl(ImageButton1);

你可能感兴趣的:(JavaScript,html,function,服务器,asp.net,button)