Handle key event on select control

Description

The following code shows how to handle key event on select control.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type="text/javascript"
  src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.css">
<script type='text/javascript'>
$( "#myselect" ).selectmenu( "refresh" );
$(document).keyup(function(e){<!--from  w ww  . j  a v a 2s  . c  o m-->
    if(e.which >= 48 && e.which <= 57){
        $("#myselect").selectmenu( "open" );//this should open the select
        $("#keyOpen").empty().text(e.which);
    }else if(e.which >= 58 && e.which <= 90){
        $("#myselect").selectmenu( "close" );//this should close the select
        $("#keyClose").empty().text(e.which);
    }
});
</script>
</head>
<body>
  <select id="myselect" data-native-menu="false">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
  </select>
  <div id="keyOpen" style="background-color: blue;"></div>
  <div id="keyClose"></div>
</body>
</html>

Click to view the demo





















Home »
  jQuery Mobile »
    Example »




Button
Button Event
Button Icon
Button Text
Checkbox
Collapsible
Date
Dialog
Event
Footer
Form
Header
Icon
Input
Layout
Listview
Listview Divider
Listview Item
Loader
mobile_settings
Navbar
Page
Page Event
Popup
Radio
Select
Slider
Switch
Textarea
Theme