Javascript jQuery更改事件未正确触发
我的输入值检测在Chrome中工作正常,但在Internet Explorer中,如果用户键入enter键,则不会触发“更改”事件。如何使它在两种浏览器上都能工作,并防止在Chrome中触发两次事件 HTMLJavascript jQuery更改事件未正确触发,javascript,jquery,html,Javascript,Jquery,Html,我的输入值检测在Chrome中工作正常,但在Internet Explorer中,如果用户键入enter键,则不会触发“更改”事件。如何使它在两种浏览器上都能工作,并防止在Chrome中触发两次事件 HTML 这已经是一个问题很久了,我不知道为什么jQuery不能自动处理它。如果浏览器支持onchange的enter键,那么似乎没有任何方法可以避免触发两个事件,因此您只需解决以下问题: $input.on('focus', function(e) { this.calcul
这已经是一个问题很久了,我不知道为什么jQuery不能自动处理它。如果浏览器支持onchange的enter键,那么似乎没有任何方法可以避免触发两个事件,因此您只需解决以下问题:
$input.on('focus', function(e) {
this.calculationDone = false;
}).on('change', function(e) {
if (!this.calculationDone) {
calculationDone = true;
$('h2').text($(this).val());
console.log('done');
//do other calculation
}
}).on('keyup', function(e) {
if(e.which != 13) return;
e.preventDefault();
$(this).trigger('change');
})
使用('keyup',event@NishitMaheta,有时一个用户想要输入几个数字,它会失去对keupcheck的关注这把小提琴可能会帮助你
var $input = $('.price');
$input.on('change', function(e) {
$('h2').text($(this).val());
//do other calculation
}).on('keyup', function(e) {
if(e.which != 13) return;
e.preventDefault();
$(this).trigger('change');
})
$input.on('focus', function(e) {
this.calculationDone = false;
}).on('change', function(e) {
if (!this.calculationDone) {
calculationDone = true;
$('h2').text($(this).val());
console.log('done');
//do other calculation
}
}).on('keyup', function(e) {
if(e.which != 13) return;
e.preventDefault();
$(this).trigger('change');
})