0

私のオートコンプリート データは {"label":"Apple iPhone 3G","values":"293"} のようになります。ユーザーがオートコンプリート オプションをクリックすると、ベースの製品ページにリダイレクトしたいと考えています。一意の ID 値について。元。iphone 3g が選択されたときに example.com/293 に移動したいのですが、現在、選択されているものではなく、入力されているものの値が取り込まれます。つまり、A と入力して iphone 4g をクリックすると、iphone 4g の正しい値は保存されず、a で始まる最初の項目の値が保存されます。または、iphone と入力して iphone 4 を選択すると、最初の iphone の値がデータベースに保存されます

http://mogulcases.com/matt/search.php

キー値の保存方法

$.widget( "custom.catcomplete", $.ui.autocomplete, {
  _renderMenu: function( ul, items ) {
    var self = this,
               currentCategory = "";

    $.each( items, function( index, item ) { 
      self._renderItem( ul, item );

      $("input[type=hidden][name=key]").val(item.values); 

    });

  }
});

値を取得する方法

var searchcode = document.getElementById('key').value;
4

1 に答える 1

0

selectイベントで何かをしてみませんか。すなわち

$( ".selector" ).autocomplete({
   select: function(event, ui) { 
    window.location = "http://example.com/" + ui.item.id //would send them to the page you want them to go if they click on this
  }
});

このようにして、ユーザーがリストから何かを選択した場合、そこからイベントを呼び出すだけで、アイテムが存在することを知ることができます。また、リストから選択しない場合は、検索ボタンをクリックするか、Enter キーを押したときに検索が実行されます。

同じ方法で select の値を変更することもできます

$( ".selector" ).autocomplete({
   select: function(event, ui) { 
    $(".selector").val(ui.item.value); //I think Autocomplete does something like this automatically so may not be needed.
    //But you could do something like this
    $("input[type=hidden][name=key1]").val(ui.item.value); 
  }
});

ドキュメントはここにあります

于 2012-08-09T21:02:37.260 に答える