簡體   English   中英

jqueryui組合框:如何獲取值?

[英]jqueryui combobox: how do I get the value?

我從http://jqueryui.com/demos/autocomplete/#combobox借來了代碼,但不知道如何獲取所選項目的值。

希望有一個簡單的直接答案,而不是在接下來的2小時內閱讀其文檔。

在Easy UI組合框中:
獲得當前值
$( '#組合框')。組合框( '的getValue')
獲取當前字符串
$( '#組合框')。組合框( '的getText')
希望這可以幫助。

$('#combobox').val() might do the trick

好,那是不正確的。 這樣做:

$( "#combobox" ).autocomplete({
   select: function(event, ui) { ... }
});

在其中執行console.log($(ui).val())或類似的操作

那么您應該可以執行以下操作之一:$('#combobox')。text()或.val()來獲取其內容。

如果您使用的是'input'元素,那么這就是我的工作方式。

<input type="text" id="comboBox" />

JavaScript的

$("#comboBox option:selected").val()

那將返回選擇的值。

$(this).combobox({ selected: function (event, obj) { 
  console.log(obj.item.value) // log val 
  window.location.href = obj.item.value; // if you are using a url then give this a go
} }); 

這可能會使事情更容易理解。

您可以使用$('#comboname').combobox('getValue')獲取值。

有關更多信息和演示,請參見http://www.jeasyui.com/demo/main/index.php?

首先設置文本框的ID,然后獲取文本框的值和下拉的選項的文本匹配它,如果期權的文本匹配,那么得到的value.you可以看到例如這里的的jsfiddle

this.input = $("<input>")
     .appendTo(this.wrapper)
     .val(value)
     .attr('placeholder', "Enter Type...")
     .attr("title", "")

     // Set Id of Input Type Text    

     .attr('id', 'Mach')
     .addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
     .autocomplete({
     delay: 0,
     minLength: 0,
     source: $.proxy(this, "_source")
     })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM