简体   繁体   English

有没有办法使用 JavaScript 手动重置 onchange 事件?

[英]Is there a way to manually reset the onchange event using JavaScript?

Is this possible?这可能吗? I tried setting selectedIndex but that didn't work.我尝试设置selectedIndex但这不起作用。

What I have is a problem with an onChange event on a touchscreen device.我遇到的是触摸屏设备上的 onChange 事件问题。 The onChange event with a selection from a dropdown works fine the first time, but doesn't seem to reset when I call the form again, even though I reset the form itself.带有从下拉列表中选择的 onChange 事件第一次工作正常,但当我再次调用表单时似乎没有重置,即使我重置了表单本身。

The problem is that the selections on the first dropdown, after the first one, depend on the onChange event calling a function to generate the next select dropdown.问题是第一个下拉列表上的选择,在第一个下拉列表之后,依赖于调用函数的 onChange 事件来生成下一个选择下拉列表。 However, on the device itself, the onChange event doesn't seem to trigger, if the item is re-selected in the first box.但是,在设备本身上,如果在第一个框中重新选择该项目,则 onChange 事件似乎不会触发。 Difficult to understand, but I thought if I could reset the onChange event for that select box element, then the onChange event would fire properly again.难以理解,但我想如果我可以重置该选择框元素的 onChange 事件,那么 onChange 事件将再次正确触发。

You want to trigger the onchange handler?您想触发 onchange 处理程序吗? document.getElementById('yourelement').onchange() . document.getElementById('yourelement').onchange()

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

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