该页面顶部和左边有用户自定义控件,其中左边控件是用于查询的,希望当在左侧输入查询条件后直接回车即响应“查询”按钮,但每次响应的却是顶部控件的第一个按钮。
我在该页面使用JAVASCRIPT:
function document.onkeydown()
{
var e=event.srcElement;
if(event.keyCode==13)
{
document.getElementById( "LeftMenu_btn_inquery ").click();
return false;
}
}
“LeftMenu_btn_inquery”是左侧控件“查询”按钮(服务器控件)的clientid,试过直接使用其id,也不对。
希望大家帮帮我吧~~~“查询”不和回车联系,客户用起来总感觉不流畅啊~~
------解决方案--------------------------------------------------------
try:
function document.onkeydown()
{
var ctlId = " <%=LeftMenu_btn_inquery.ClientID%> ";
var e=event.srcElement;
if(event.keyCode==13)
{
document.getElementById(ctlId ).click();
return false;
}
}
------解决方案--------------------------------------------------------
做个了例子,楼主直接拷下来就可以看结果
test.aspx:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "test.aspx.cs " Inherits= "test " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script language= "javascript ">
function document.onkeydown()
{
var e=event.srcElement;
if(event.keyCode==13)
{
document.getElementById( "btOk ").click();
return false;
}
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:Button ID= "btOk " runat= "server " Text= "查询 " OnClick = "btn_Click "/>
</div>
</form>
</body>
</html>
test.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
Response.Write( " <script language= 'javascript '> alert( '成功 '); </script> ");
}
}
试试看