简体   繁体   English

我应该使用哪个HTML事件监听器?

[英]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.

相关问题 JS事件触发器应使用哪个HTML5标签 - Which HTML5 tag should I use for a JS event trigger 我应该为用户滑动使用什么 jquery 事件侦听器? - What jquery event listener should i use for a user swipe? 在事件监听器中管理逻辑; (我应该如何添加侦听器?还是应该使用条件“网守”?) - Managing Logic Inside Event Listeners; (How Should I Add a Listener? OR Should I Use a Conditional “gatekeeper” Instead?) 我应该将哪个“事件”与 <input/> iOS / Android上的元素? - Which 'event' should I use with an <input/> element on an iOS/Android? 我应该使用哪个Event.target属性? - Which Event.target Property Should I Use? 我应将哪种事件类型与“范围”类型的输入一起使用? - Which event type should I use with inputs of type 'range'? 如何在js中使用事件监听器链接到html? - How to use event listener in js to link to html? 我应该使用哪个事件侦听器将选择菜单绑定到日历,如何使用? - What event listener should I use to tie my select menu to my calendar and how? 我应该使用什么按钮事件来确认 html 表单? - What button event should I use to confirm a html form? 当页面上有多个元素时,即使我使用它们的 ID,JS 事件侦听器也不起作用。 (这是独一无二的) - JS Event listener does not work when there are multiple elements on the page even if i use their ID. ( which is unique )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM