重点是在另一个控制,但pressing输入presses的默认按钮 [英] focus is on another control but pressing enter presses the default button
问题描述
我要被点击超链接,目前具有焦点,当我preSS回车键。
有人可以帮助我的JavaScript code?
我已经写在JavaScript中的code,实际上试图点击一个按钮,当焦点在那个按钮 -
IF((重点code == 13))
{
evt.returnValue = FALSE;
evt.cancel = TRUE;
如果((document.activeElement.name ='btnChangeRep')及!&放大器;
(!document.activeElement.name ='btnSubmitAndOpen')及与放大器;
(!document.activeElement.name ='hypTaxID')及与放大器; !document.activeElement.name ='hypCoTaxID')及与放大器;
(document.activeElement.name!='hypFormerRegSearch'))
{
BTN =的document.getElementById('btnSubmit按钮');
如果(BTN == NULL)
{
的document.getElementById('btnSave')点击()。
}
其他
{
的document.getElementById('btnSubmit按钮')点击()。
}
}
其他
{
的document.getElementById(document.activeElement.name)。点击();
}
在Firefox,但在IE链接
这是工作的罚款是不开放的preSS的输入进不去。
有人可以帮我为我要去的地方错了
修改 HTML超链接
< ASP:超链接ID =hypTaxID=服务器>< / ASP:超链接>
在链接上点击调用将触发该链接任何JavaScript单击事件,但并不总是导致导航发生。
在过去,我不得不使用JavaScript做导航。你会想要像下面这样。 (我还使用jQuery简化它的一些东西)
IF((重点code == 13))
{
evt.returnValue = FALSE;
evt.cancel = TRUE; 如果((document.activeElement.name ='btnChangeRep')及!&放大器;
(!document.activeElement.name ='btnSubmitAndOpen')及与放大器;
(!document.activeElement.name ='hypTaxID')及与放大器;
!document.activeElement.name ='hypCoTaxID')及与放大器;
(document.activeElement.name!='hypFormerRegSearch'))
{
BTN =的document.getElementById('btnSubmit按钮');
如果(BTN == NULL)
{
的document.getElementById('btnSave')点击()。
}
其他
{
的document.getElementById('btnSubmit按钮')点击()。
}
}
其他
{
/ *新的code * /
VAR链接=的document.getElementById(document.activeElement.name).getAttribute(的href);
document.location.href =链接;
}
}
另外,还要确保你的ASP.net元素的ID是你所期望的。 Web表单是臭名昭著的ID和名字改编。
我也将评估你为什么不使用ASP.net处理这种在服务器端。采用ASP.net面板可以设置的默认按钮使按钮被点击回车键时为pressed。
I want a hyperlink, which currently have focus, to be clicked when I press enter key.
Can somebody help me with the javascript code?
I do have written a code in javascript that actually tries to click a button when focus is on that button -
if ((KeyCode == 13))
{
evt.returnValue=false;
evt.cancel = true;
if((document.activeElement.name != 'btnChangeRep') &&
(document.activeElement.name != 'btnSubmitAndOpen') &&
(document.activeElement.name != 'hypTaxID') && document.activeElement.name != 'hypCoTaxID') &&
(document.activeElement.name != 'hypFormerRegSearch'))
{
btn = document.getElementById('btnSubmit');
if (btn == null)
{
document.getElementById('btnSave').click();
}
else
{
document.getElementById('btnSubmit').click();
}
}
else
{
document.getElementById(document.activeElement.name).click();
}
It is working fine in firefox but in IE link is not opening on press of enter anyhow.
Can someone please help me as where I am going wrong
EDIT HTML for hyperlink
<asp:hyperlink id="hypTaxID" runat="server"></asp:hyperlink>
Calling click on a link will fire any javascript click events for the link but not always cause the navigation to happen.
In the past I have had to use javascript to do the navigation. You would want something like the following. (I'd also use jquery to simplify it some what)
if ((KeyCode == 13))
{
evt.returnValue=false;
evt.cancel = true;
if((document.activeElement.name != 'btnChangeRep') &&
(document.activeElement.name != 'btnSubmitAndOpen') &&
(document.activeElement.name != 'hypTaxID') &&
document.activeElement.name != 'hypCoTaxID') &&
(document.activeElement.name != 'hypFormerRegSearch'))
{
btn = document.getElementById('btnSubmit');
if (btn == null)
{
document.getElementById('btnSave').click();
}
else
{
document.getElementById('btnSubmit').click();
}
}
else
{
/*new code*/
var link = document.getElementById(document.activeElement.name).getAttribute("href");
document.location.href = link;
}
}
Also make sure that the ID's of your ASP.net elements are what you expect. Webforms are notorious for ID and name mangling.
I would also evaluate why you are not using ASP.net to handle this on the serverside. Using an ASP.net panel lets you set a default button for the panel so that button is clicked the when enter button is pressed.
这篇关于重点是在另一个控制,但pressing输入presses的默认按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!