ASP.NET MVC Ajax - 是否可以使用键盘输入执行 -GENERATED- Ajax 链接?
当用户按下键盘上的某个键时,是否有人能够执行生成的 Ajax.ActionLink?(这是辅助功能所必需的)
注意:我正在使用 ASP。 NET MVC + Microsoft Js 库 (...Ajax.js / ...MvcAjax.js) + jQuery
Javascript 捕获按键 (IE + Firefox)
$(document).keypress(function(event) {
if(event.keyCode == 27) {
//execution here
var a = document.getElementById('linkid');
}
});
由 ASP.NET MVC 生成的 Html (Ajax.ActionLink())
<a id="linkid" href="/controller/action" onclick="
Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event),
{ insertionMode: Sys.Mvc.InsertionMode.replace,
updateTargetId: 'SomeDivId' });
">LinkText</a>
以下不是我要找的内容,这不起作用!
$(document).keypress(function(event) {
if(event.keyCode == 27) {
var a = document.getElementById('linkid');
a.onclick(); //doesn't exist in Firefox
a.click(); //doesn't "work" in Firefox (reference to "this" [a] is needed .NET MVC javascript)
a["onclick"](); //same as .onclick()
a["click"](); //same as .click()
//or even:
a.onclick.apply(a); //doesn't exist in Firefox
a.click.apply(a); //Somehow keeps "this" reference, but throws Sys.ArgumentUndefinedException
}
});
Is anybody able to -execute- a generated Ajax.ActionLink when a user presses a key on the keyboard? (This is needed for accessibility)
NOTE: I'm using ASP.NET MVC + Microsoft Js libraries (...Ajax.js / ...MvcAjax.js) + jQuery
Javascript to capture keypress (IE + Firefox)
$(document).keypress(function(event) {
if(event.keyCode == 27) {
//execution here
var a = document.getElementById('linkid');
}
});
Html generated by ASP.NET MVC (Ajax.ActionLink())
<a id="linkid" href="/controller/action" onclick="
Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event),
{ insertionMode: Sys.Mvc.InsertionMode.replace,
updateTargetId: 'SomeDivId' });
">LinkText</a>
The following is not what i'm looking for, this doesn't work!
$(document).keypress(function(event) {
if(event.keyCode == 27) {
var a = document.getElementById('linkid');
a.onclick(); //doesn't exist in Firefox
a.click(); //doesn't "work" in Firefox (reference to "this" [a] is needed .NET MVC javascript)
a["onclick"](); //same as .onclick()
a["click"](); //same as .click()
//or even:
a.onclick.apply(a); //doesn't exist in Firefox
a.click.apply(a); //Somehow keeps "this" reference, but throws Sys.ArgumentUndefinedException
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过使用 jQuery 的触发机制吗?
如果做不到这一点,您可以只调用 href,这将执行完整的回发,但如果该操作被编写为处理 AJAX 和非 AJAX 请求,则应该完成所需的操作。
Have you tried using jQuery's trigger mechanism?
Failing that, you could just invoke the href, which will do a full postback, but should accomplish the desired action if the action is written to handle both AJAX and non-AJAX requests.
请尝试这个:
Please Try this: