我有这段JavaScript:
jQuery(document).ready(function(){
const select = $('...'); //it's a simple select
const input = $('...'); //it's a simple input
select.change(doSomething());
input.change(doSomething());
function doSomething(){
console.log("yes");
}
}
yes
加载页面后,在控制台中将打印两次。
当我更改select或input的值时,yes
不再在控制台中打印出来。
jquery version: 3.4.0
您应该将doSomething
功能传递给更改参数。不是它的执行结果。
select.change(doSomething);
input.change(doSomething);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句