简体   繁体   中英

Event for SELECT onchange with keyboard

I have an onchange event on an HTML SELECT control which calls a JavaScript function. This works if I select a new option from the open list with the mouse, or if I drop down the SELECT control and then select an option with the mouse or select with the keyboard and press ENTER.

How can I get the function to run if the SELECT control is NOT open and I simply scroll up or down with the cursor keys through the various options. onblur does nothing and onkeypress result in some strange results in which values got out of sync.

The onkeyup event will solve this:

<select name="theName" id="theID" onchange="javascript:theFunction();" onkeyup="javascript:theFunction();">
<option value="A">Choice A</option>
<option value="B">Choice B</option>
<option value="C">Choice C</option>
</select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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