キーボードの下矢印キーのselect2で、サーバー呼び出しを回避する必要があります。サーバー呼び出しがリストを再度更新し、下矢印キーの機能が機能しないためですが、方法はありませんか? select2 についての予備知識がないので、select2.js でこのイベントが処理される場所を教えてください。
1239 次
1 に答える
0
そのコードを試して、左矢印キーを押して ajax リクエストを配置すると、それが表示され、好きなように使用できます....
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
function leftArrowPressed() {
alert("leftArrowPressed" );
//window.location = prevUrl
$.ajax({
type: "POST",
url: "your url ",
data: "",
success: function() {
alert(" Successfully submit request");
},
error: function() {
alert("Error Occurred");
}
});
}
function rightArrowPressed() {
alert("rightArrowPressed" );
window.location = nextUrl
}
function topArrowPressed() {
alert("topArrowPressed" );
window.location = prevUrl
}
function downArrowPressed() {
alert("downArrowPressed" );
window.location = nextUrl
}
document.onkeydown = function(evt) {
var nextPage = $("#next_page_link")
var prevPage = $("#previous_page_link")
nextUrl = nextPage.attr("href")
prevUrl = prevPage.attr("href")
evt = evt || window.event;
switch (evt.keyCode) {
case 37:
leftArrowPressed(nextUrl);
break;
case 38:
topArrowPressed(nextUrl);
break;
case 39:
rightArrowPressed(prevUrl);
break;
case 40:
downArrowPressed(prevUrl);
break;
}
};
</script>
</head>
<body>
<p>
<a id="previous_page_link" href="http://www.latest-tutorial.com">Latest Tutorials</a>
<a id="next_page_link" href="http://www.zeeshanakhter.com">Zeeshan Akhter</a>
</p>
</body>
</html>
于 2013-12-10T20:41:22.770 に答える