Okay, so I need to create the code to ensure that when certain keys are pressed triggers the event as if a button were clicked. following the link through that button when they keyboard keys are pressed.
好的,所以我需要创建代码以确保在按下某些键时触发事件,就好像单击了一个按钮一样。当按下键盘键时,通过该按钮链接。
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();
}
});
2 个解决方案
#1
0
You might want to have a look at the Hotkeys library for binding key events
您可能希望查看热键库以绑定键事件
#2
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>
#1
0
You might want to have a look at the Hotkeys library for binding key events
您可能希望查看热键库以绑定键事件
#2
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>