我尝试使用 .has()
选择器仅在我的 body 有图像时执行关键控件。
这就是我目前正在尝试的方法,但它不起作用。
if ($('body').has('img')){
$(document).on('keyup', function (event) {
if (event.which === 37) {
console.log('test');
}
});
}
最佳答案
试试这个
if ($('body img').length) {
}
关于javascript - 将 .has() 与 keyup 事件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19029075/