2

ホットキーにはこのjqueryhttps://github.com/tzuryby/jquery.hotkeysを使用します

どうか、これを「追加」機能と呼ぶ方法を教えてください。

<script type = "text/javascript" >
    function add(int) {
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("add").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "method.php?a=" + int, true);
        xmlhttp.send();
    } 
</script>

たとえば、アラートではなく、addjavasctiptを呼び出す必要があります。

<script src="jquery-1.4.2.js"></script>
<script src="jquery.hotkeys.js"></script >

<script> 
    $(document).bind('keydown', 'ctrl + k', function() {
       alert('Teskt hotkey!'); 
       // I need processing javasctipt named "add", not alert
    });
</script>
4

1 に答える 1

0

バージョン1.4.2は減価償却されているため、 jquery 1.8.3(ここからダウンロードできます)を使用することをお勧めします。これは、関数を呼び出す方法です。

JAVASCRIPT:

<script src="jquery-1.4.2.js"></script>
<script src="jquery.hotkeys.js"></script>
<script type="text/javascript">
//here you are declaring the function
function add(int) {
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("add").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "method.php?a=" + int, true);
    xmlhttp.send();
} 

$(document).ready(function(){ 
//when you use jquery, 
//it is good practice to wait until the document is ready.
    $(document).bind('keydown', 'ctrl + k', function() {
    //the add function requires an argument, so make sure to provide one.
        add(1);
    });
});
</script>

これがお役に立てば幸いです。ご不明な点がありましたらお知らせください。ハッピーコーディング!

于 2012-11-28T04:02:53.193 に答える