Javascript jquery上的更改和输入函数多次运行
在我的代码中有140个选择器和2个事件(更改、输入) 当我减少选择器的数量时,返回时间也会减少,但我需要所有选择器。Javascript jquery上的更改和输入函数多次运行,javascript,jquery,function,jquery-selectors,Javascript,Jquery,Function,Jquery Selectors,在我的代码中有140个选择器和2个事件(更改、输入) 当我减少选择器的数量时,返回时间也会减少,但我需要所有选择器。 我用了这些方法 $("#selector1, #selector2, #selector3, ...... #selector139, #selector140").off('change input').on('change input',function(e){ console.log('test')//it returns 28 times //My j
我用了这些方法
$("#selector1, #selector2, #selector3, ...... #selector139, #selector140").off('change input').on('change input',function(e){
console.log('test')//it returns 28 times
//My jquery code
}
但输入事件不起作用
$("#selector1, #selector2, #selector3, ...... #selector139, #selector140").on('change input', function(e){
if(e.handled !== true)
{
//Code
e.handled = true;
}
});
但这种方法也不起作用
我使用了one()
函数,但它不能正常工作。
有没有办法解决这个问题?
谢谢 最好改用
class
。
只需向输入中添加一个类,如下所示:<input class="someclass" type="text" />
为什么不改用类呢?你不应该有那么多的ID,这正是我要建议的@CertainPerformanceAll元素是
输入
?如果不是,当然输入事件不起作用。所有元素都是100%的输入
<input class="someclass" type="text" />
$('.someclass').on('input change',function() {
//do what you want
});