2012-02-26 41 views
1

我有一個自動完成組合框包含來自mysql的選項,組合框包含供應商的名稱和它的id,其中一旦用戶從組合框中選擇的id將被存儲在一個隱藏的領域,然後存儲在一個會話。我想知道的是,如何根據會話設置基於autocomplete combobx的默認文本/值?如何設置jquery ui組合框選定的值或默認文本?

Ex。 Session = 25; SupplierText =「Stackoverflow」ID = 25 當用戶點擊一個新選項卡時,該頁面將自動顯示組合框以及基於會話的適當文本。在這種情況下,組合框應具有Stackoverflow的文本值。只要能夠顯示文字就夠了。

先生/女士您的回答會有很大的幫助。

+0

你可以使用像https://github.com/carhartl/jquery-cookie – elclanrs 2012-02-26 23:47:35

回答

1

也許你需要像例如this

像例如:

$("#yourselector").autocomplete({ 
      source: "your URL", 
      minLength: 2, 
      select: function(event, ui) { 
       $('#selector').val(ui.item.YourDataResponse); 
       $('#selector').val(ui.item.YourDataResponse); 
      } 
}); 

ui.item是jQuery UI的默認..

1

我發現具有 「選擇」 選項創建組合框時的屬性將在組合框中選定。您可以通過銷燬組合框來設置選定的選項,從選項中刪除「selected」屬性並將該屬性添加到要選擇的選項,然後再次創建組合框。

這裏是我的代碼:

// Destroy the combobox 
$(".combobox").combobox("destroy"); 

// Unselect the currently selected option 
$("#selectlist option:selected").removeAttr("selected"); 

// Select the option you want to select 
$("#selectlist option[value='test']").attr("selected", "selected"); 

// Create the combobox again 
$(".combobox").combobox(); 
0

如果你只是想創建組合框後設置組合框輸入的值,可以設置選擇,然後價值...

$(".ui-combobox-input").val($("#select option:selected").text());