确定是无法识别的表达式,但是我该如何解决?
$('body').on('keydown', 'input[class=form-control amount]', function (e) {
if (e.which === 110 | e.which === 190) {
e.preventDefault();
return false;
}
});
答案 0 :(得分:2)
尝试一下:
$('body').on('keydown', 'input.form-control.amount', function (e) {
if (e.which === 110 | e.which === 190) {
e.preventDefault();
return false;
}
});
答案 1 :(得分:1)
您可以像这样在类周围添加引号:
class="form-control amount"
指定class属性具有2个类:
$('body').on('keydown', 'input[class="form-control amount"]', function (e) {
console.log("key down");
if (e.which === 110 | e.which === 190) {
e.preventDefault();
return false;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="form-control amount" placeholder="logs"/>
<input type="text" class="foo" placeholder="no logs"/>