gpt4 book ai didi

jQuery热键调用函数

转载 作者:行者123 更新时间:2023-12-01 05:57:59 25 4
gpt4 key购买 nike

我使用这个jquery https://github.com/tzuryby/jquery.hotkeys用于热键。

请问我如何调用这个“add”函数:

<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>

例如,我需要调用add javasctipt,而不是alert:

<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>

最佳答案

我建议您使用 jquery 1.8.3 ( can download here ),因为版本 1.4.2 已弃用。这是您应该如何调用该函数:

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>

希望这对您有所帮助,如果您有任何疑问,请告诉我。快乐编码!

关于jQuery热键调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13595103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com