在键盘上的 select2 中按下向下箭头键,然后我必须避免服务器调用,因为服务器调用再次刷新列表并且我的向下箭头键功能不起作用,但不知道如何?我对 select2 没有任何先验知识,所以请让我知道这个事件在 select2.js 中在哪里处理?
试试我把 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>