[英]Which HTML event listener should I use?
I have a web page that interacts with two servlets and consists therefore of two forms. 我有一个与两个servlet交互的网页,因此由两种形式组成。 First form sends data to servlet one to prepare some data to fill drop down menus in the second form depending on the selection. 第一种形式将数据发送到servlet,以准备一些数据来填充第二种形式的下拉菜单,具体取决于选择。 Second form holds four drop down menus which represent different attributes of an object (and interacts with servlet two). 第二种形式包含四个下拉菜单,分别代表一个对象的不同属性(并与servlet进行交互)。
Not all combinations of selections from the drop down menus are valid in step two, therefore I want to show some texts beneath the drop downs to make the user aware of invalid combinations. 在第二步中,并非下拉菜单中的所有选择组合都有效,因此我想在下拉菜单下方显示一些文本,以使用户知道无效的组合。 I used onchange="checkValues()"
to generate these texts, which works fine per se. 我使用onchange="checkValues()"
来生成这些文本,其本身工作正常。 ( onsubmit()
later prevents invalid combinations from submitting) ( onsubmit()
稍后可防止提交无效的组合)
The Problem : Unfortunately, the preset combination is an invalid one. 问题 :不幸的是,预设组合是无效的。 I want to show the texts also, when second form is loaded for the first time. 我也想在第一次加载第二种表单时显示这些文本。 I tried to use onsubmit="checkValues()"
in form one, but it has no influence on the texts as the drop down menus (and therefore the values to be checked) are loaded after the submit. 我尝试在形式一中使用onsubmit="checkValues()"
,但由于在提交后加载了下拉菜单(因此要检查的值),因此它对文本没有影响。
Which event would be more appropriate to cover onchange
and the first combination after initialization of the drop downs? 下拉菜单初始化后 ,哪个事件更适合覆盖onchange
和第一个组合 ?
Use an other preset combination is not an option. 不能使用其他预设组合。
The best way to do this would be to wrap your site in a single div and attach a single event listener to that div. 最好的方法是将您的网站包装在单个div中,并将单个事件侦听器附加到该div。
Then you can listen to everything without having to make a ton of different event listeners and slowing down your site. 然后,您可以聆听所有内容,而不必创建大量不同的事件侦听器,并且可以降低网站速度。 You can tell where it came from by evaluating the ID as long as you set one, of course 只要设置一个ID,您就可以通过评估ID来分辨它的来源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.