ユーザーがキーボードのキーを押したときに、生成された 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 ( Ajax.ActionLink() )によって生成された HTML
<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
}
});