我有一个 html 元素:
...
<div class="preferences">
...
<button class="menuButton cpnScanPressed" id="btnScanCpn">Scan</button>
...
</div>
...
并在其上绑定一个事件:
$('.preferences').on('click', '#btnScanCpn', handleScanCpn);
现在我想在按下 ESC 时触发该事件:
/* discard changes if pressing esc */
input.keydown(function(e) {
if (e.keyCode == 27) {
e.preventDefault();
console.log("DEBUG"); // console says:"DEBUG"
console.log($(".cpnScanPressed#btnScanDps")); // console says:"jQuery( )"
$("#btnScanDps").trigger('click'); // wont fire!
}
});
那么似乎有什么问题?!似乎选择器不起作用?!我不明白。。