好的,所以我需要创建代码以确保在按下某些键时触发事件,就好像单击了一个按钮一样。按下键盘键时按下该按钮的链接。
el.on('keypress', function(event){
$('li').find('li.next');
if (keycode == 39) {
$('.next').click();
}
});
el.on('keypress', function(event){
$('li').find('li.prev');
if (keycode == 37){
$('.prev').click();
}
});
答案 0 :(得分:0)
您可能希望查看热键库以结合键事件
答案 1 :(得分:0)
JS
el.on('keyup', function (event) {
var $paginationList = el.find('ul.pagination');
const LeftKeyCode = 37;
const RightKeyCode = 39;
var keyCode = event.keyCode || event.which;
if (keyCode == LeftKeyCode){
$paginationList.find('li.prev').find('a').click();
}
if (keyCode == RightKeyCode){
$paginationList.find('li.next').find('a').click();
}
HTML
<li class="prev">
<a href="<?= $pageUrl ?>" class="widget-modal-drilldown"> Previous</a>
</li>
<li class="next">
<a href="<?= $pageUrl ?>" class="widget-modal-drilldown">Next</a>
</li>