2014-12-02 34 views

回答

1

是的,这可以通过下面的示例代码来实现。我已经用Firefox测试过了。

我还没有找到任何其他解决方案,但它的工作原理。你可以在jsFiddle here找到相同的代码。

$(function() { 
 
    $('select').on('keyup', function (event) { 
 
     //console.log(event); 
 
     if (event.keyCode == '32') { 
 
      var selected = $(this)[0].selectedIndex; 
 
      //console.log(selected); 
 
      $("select").prop('selectedIndex', selected); 
 
      $(this).blur(); 
 
     } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<select> 
 
    <option>1</option> 
 
    <option>2</option> 
 
    <option>3</option> 
 
    <option>4</option> 
 
    <option>5</option> 
 
</select>

+0

您的解决方案非常完美。 – user3246489 2014-12-02 19:41:14

相关问题