English 中文(简体)
Jquery autocomplete:使用表格选择第一项目,继续侧重于搜索箱
原标题:Jquery autocomplete: using tab to select first item and remain focus on search box

当我使用JQuery UI汽车包件时,我需要用在汽车结果中的第一个项目的表格钥匙,包括一个空间,然后允许用户继续打字。

<div class="ui-widget">
  <form id="searchbox" method="GET" action="http://duckduckgo.com/">
    <input id="search" type="text" name="q">
    <input id="submit" type="submit" value="Search">
  </form>
</div>
<script>
var tabKey = 9;
$( #search ).autocomplete({
    source: [  this ,  that ,  foobar  ],
    delay: 0,
    selectFirst: true,
    select: function(event, ui) { if (event.keyCode == tabKey) { 
      $( #search ).focus().select();
    } }
});
// without this, the tab key doesn t trigger an event                                                                                       
$( .ui-autocomplete ).keypress(function(event) {});
</script>

换言之,在上述例子中,如果有人打上了“th”,他们就会看到汽车选择中的“这种”和“这种”。 点名表将添加“(注)”投入和重点内容的内容。

Can someone give me a pointer as to what I ve missed? I do not know Javascript very well, so small words are good :)

也许从欧洲复兴开发银行科处获得更有用的信息(频率1.7.2):

<script src="js/jquery-latest.js"></script>
<script src="js/jquery-ui-1.8.20.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.20.custom.css" /> 

Edit: It appears that autoFocus: true will get me partway there. Now if I can just figure out how to keep focus on the input box.

最佳回答
问题回答

我使用此(发言稿):

$("#autocomplete").keydown (event) ->
    if event.keyCode != $.ui.keyCode.TAB then return true
    $(this).trigger($.Event  keydown , keyCode: $.ui.keyCode.DOWN)
    false

Autofocus将选择第一种记录,以进行下游搜查。

那么,您的法典才需要列入<条码>autofocus:真实,。 如下:

$( #search ).autocomplete({
    source: url,
    delay: 0,
    autoFocus: true,
    select: function( event, ui ) {
        $( "#id" ).val( ui.item.id );
        $(this).closest( form ).submit();
    },
    focus: function( event, ui ) { event.preventDefault(); }
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签