gpt4 book ai didi

javascript - 如何在按键事件上运行一个函数

转载 作者:行者123 更新时间:2023-11-30 08:54:53 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
jQuery keypress() event not firing?

我正在使用 wordpress 作为我的 cms

我也在开发一个投票系统

这是我用于投票功能的jquery

我如何在按键事件上运行这个函数?

例如,如果有人按下“A”键,此功能会自动运行

我谷歌了至少半小时,但没有找到任何相关结果

 <script type="text/javascript">
/* <![CDATA[ */
(function($) {
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

$(document).ready(function(){
$("body").on('click', '.vote-btn:not(.disabled)', function () {
var el = $(this),
nonce = $("input#voting_nonce", el.parent()).val(),
id = el.attr('id').replace(/vote-/, ''); // get the Post ID

el.html('<span id="loader"></span>');
var data = {
action: 'add_votes_options',
nonce: nonce,
postid: id,
ip: '<?php echo $_SERVER['REMOTE_ADDR']; ?>'
};
$.post('<?php echo admin_url('admin-ajax.php'); ?>', data,
function(response){
console.log( response );

if(response!="-1") {

el.html('<img src="<?php get_bloginfo('url'); ?>/wp- content/themes/9GAG/happysimily.png">').unbind('click').addClass('clickedyellow');
$('.vote-btn', el.closest('div')).addClass('disabled');
$("#vote", el.closest('article')).addClass('clickedlove');



if(response=="null") {
alert("A vote has already been registered to this IP address.");

} else {
$("#votecounter", el.closest('article')).html(response);


}
var cookie = getCookie("better_votes");
if(!cookie) {
var newcookie = id;
} else {
var newcookie = cookie + "," + id;
}
setCookie("better_votes", newcookie, 0);
} else {
alert("There was a problem registering your vote. Please try again later or enable browser cookies.");
}

});

return false;
});

})
})(jQuery);




/* ]]> */
</script>

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