0

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

4

1 回答 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 回答