简体   繁体   English

如何更改struts2选择下拉列表的默认行为

[英]how to change the default behaviour of struts2 select dropdown list

I have a struts2 select drop down list which has numbers. 我有一个带有数字的struts2 select下拉列表。 I need to select a particular number in it using keyboard numbers which was default and it works but in this I need more specific to disable the behaviour that is while say for an example if I need 25 I can type 2 and 5 but if I type 2 and with a delay in typing 5, then it is not working so only 20 is selected instead of 25. 我需要使用默认的键盘数字在其中选择一个特定的数字,并且它可以工作,但是在这种情况下,我需要更具体地禁用该行为,例如,如果我需要25,则可以键入2和5,但是如果键入2,但输入5时有延迟,则它不起作用,因此仅选择了20,而不是25。

Another one is I need to disable the behaviour that when 2 is pressed and with some delay 2 is pressed again then it starts increments the number by 1 like 20,21,22... and so on up to 29. 另一个是我需要禁用以下行为:当按下2并再次延迟2时,它将开始将数字递增1,例如20,21,22 ...依此类推,直到29。

The behaviour that while I needed is that the struts2 drop down list should only select what I type exactly. 我需要的行为是struts2下拉列表应仅选择我确切键入的内容。

<s:select list="#{'0':'00','1':'01','2':'02','3':'03','4':'04','5':'05','6':'06','7':'07','8':'08',                 '9':'09','10':'10','11':'11','12':'12','13':'13','14':'14','15':'15','16':'16','17':'17','18':'18','19':'19','20':'20','21':'21','22':'22','23':'23','24':'24'}"  
name="workedHours" cssClass=" disable inputboxsmall" id="workedHours" onchange="calcTotTime()"/>

That is browser-specific, Struts2 is not involved at all; 那是特定于浏览器的,根本不涉及Struts2。

for example, Firefox behaves like you described since very old versions, while in IE6 (!) if you press 2 and 5, he looks for "starting with 2" and then "starting with 5" (it will never find 25 by keyboard). 例如,Firefox的行为与您从非常旧的版本开始所描述的行为相同,而在IE6(!)中,如果您按2和5,他将查找“以2开头”然后是“以5开头”(它将永远不会通过键盘找到25)。 。

You can use jQuery to add the custom behavior to your Selects, once the page is ready. 页面准备就绪后,您可以使用jQuery将自定义行为添加到“选择”中。

For example, add a javascript function call in onkeyup event, that remember the previously digited characters, append the new character to them and re-assign the selected attribute to the new corresponding element. 例如,在onkeyup事件中添加一个javascript函数调用,该函数可以记住以前数字的字符,将新字符附加到它们之后,然后将selected属性重新分配给新的对应元素。

Then you would have to handle the exceptions (no element matches, do nothing or what ?), and decide how to make possible to the user to re-start from the beginning. 然后,您将不得不处理异常(没有元素匹配,什么也不做或做什么?),并决定如何使用户能够从头开始重新启动。 With a timer, like browsers do, you haven't this problem, but if you override the timer, you should find another way (hot-key or something). 与浏览器一样,使用计时器也不会出现此问题,但是如果您覆盖计时器,则应该找到另一种方法(热键或其他方法)。

Personally, i don't think that overriding browsers behavior is a good thing, especially because they're already optimized for the most of the use-cases... 就个人而言,我不认为覆盖浏览器的行为是一件好事,尤其是因为它们已经针对大多数用例进行了优化...

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

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