繁体   English   中英

如何一次触发所有输入的onchange事件?

[英]How to trigger onchange event of all input at once?

假设我有一个在单击特定按钮时自动创建或生成的输入...

假设生成的输入是......

<input class='myinput' type='text' onchange='functionName($id,this.value)' />
<input class='myinput' type='text' onchange='anotherFunctionName($id,this.value)' />
<input class='myinput' type='text' onchange='newFunctionName($id,this.value)' />
<input class='myinput' type='text' onchange='anotherNewFunctionName($id,this.value)' />
<input class='myinput' type='datetime-local' onchange='...($id,this.value)' />
<input class='myinput' type='text' onchange='...($id,this.value)' />
<input class='myinput' type='text' onchange='...($id,this.value)' />
<input class='myinput' type='datetime-local' onchange='...($id,this.value)' />
...

这些输入具有不同的类型,并且在OnChange事件上调用了特定的函数。 有时它不需要更改值,我的问题是它只会保存OnChange事件上的数据。

是否可以使用 javascript 或 jquery 一次在这些输入上触发OnChange事件?

Jquery:

$('input[type=text]').trigger('change');

使用触发器尝试使用 class 名称,

$('.myinput').trigger("Click");

查看此链接https://api.jquery.com/trigger/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM