使用Javascript:回车键preSS [英] Javascript : Enter Key Press
问题描述
早上好...
我正在使用的每一页Java脚本触发<大骨节病>输入骨节病>键preSS文本框内部事件。
这是工作的罚款。现在我要放置code在的.js
文件进行全球访问。
I am using java script in each page to trigger the Enter key press Event inside the textbox.
It is working fine. Now i want to place the code in the .js
file for global access.
function EnterKeyPress(id,e) {
// look for window.event in case event isn't passed in
if (window.event) { e = window.event; }
if (e.keyCode == 13 || e.keyCode == 121) {
window.document.getElementById('<%= ibtnSubmit.ClientID %>').click();
}
}
我不想硬code中的控件ID。任何人都可以帮我请..
I dont want to hard code the control id. Can anybody help me please..
推荐答案
您可以使用您的标识的参数,而不是控件ID,当你使用你的页面此功能,您可以通过控件ID作为一个参数:
You can use your id parameter instead of the ControlID, and when you use this function in your pages, you can pass the ControlID as a parameter:
function EnterKeyPress(id,e) {
if (window.event) { e = window.event; }
if (e.keyCode == 13 || e.keyCode == 121) {
document.getElementById(id).click();
}
}
您正在使用ASP .NET,所以在你的code-身后您可以分配的关键preSS事件:
You are using ASP .NET, so in your code-behind you can assign the keypress event:
TextBox1.Attributes.Add("onkeypress",
string.Format("EnterPressKey('{0}', event);", ibtnSubmit.ClientID));
别急,该功能基于ASP .NET已经完成,你可以使用的 ASP:面板控制来包装你的通用控件,你可以指定的 DefaultButton 为面板指示被点击的按钮,当Panel控件具有焦点并且用户presses的<大骨节病>输入骨节病>键。
But wait, that functionality is already done on ASP .NET, you can use ASP:Panel controls to wrap your common controls, and you can assign a DefaultButton for the panel to indicate which button gets clicked when the Panel control has focus and the user presses the Enter key.
这篇关于使用Javascript:回车键preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!