Tag: jquery select2

将项目dynamic添加到使用AJAX的jQuery Select2控件

我有一个jQuery的Select2控件,使用AJAX来填充: <input type="text" name="select2" id="select2" style='width:400px' value="999"> var initialSelection = { id: '999', text:"Some initial option"}; $("#select2").select2({ placeholder: "Select Option", minimumInputLength: 2, ajax: { url: "/servletToGetMyData", dataType: 'json', data: function (term, page) { return { term: term }; }, results: function (data, page) { return { results: data.results} } }, initSelection : function(element, callback){ callback(initialSelection); […]

如何在多值select中设置select的值在Jquery-Select2中。

大家好我绑定我的下拉与Jquery-Select2。 它的工作正常,但现在我需要通过使用Jquery-Select2绑定我的多值select框。 我的DropDwon <div class="divright"> <select id="drp_Books_Ill_Illustrations" class="leaderMultiSelctdropdown Books_Illustrations" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a">Illustrations</option> <option value="b">Maps</option> <option value="c">Portraits</option> </select> </div> 从这个链接http://ivaynberg.github.com/select2/我使用多值select框,我可以绑定我的dropdwon $("dropdownid").Select2() 它的工作正常,但现在我需要得到select的值到我的下拉编辑模式所以我使用这个例子 $(".Books_Illustrations").select2("val", ["a", "c"]); 它的工作,但我怎么能修复我的select,因为用户可以select任何东西所以我不能写一个,静态这就是为什么我需要dynamic地绑定我的选定值编辑模式。 我想现在你们都清楚我的要求了。 请让我知道,如果你需要进一步清除。

如何更改select2框高度

我喜欢从https://github.com/ivaynberg/select2 select2框我使用格式:选项来格式化每个元素,它看起来不错。 一切都很好,除了由于图像select的元素大于select框的高度。 我知道如何改变宽度,但是如何改变高度,以便在元素被选中之后,它显示完整的东西(大约150px) 这是我的开始: <script> $("#selboxChild").select2({ matcher: function(term, text) { var t = (js_child_sponsors[text] ? js_child_sponsors[text] : text); return t.toUpperCase().indexOf(term.toUpperCase()) >= 0; }, formatResult: formatChild, formatSelection: formatChild, escapeMarkup: function(m) { return m; } }); </script> 这是我的select框 <select id="selboxChild" style="width: 300px; height: 200px"> <option value="">No child attached</option> </select> 澄清:我不希望每个选项的高度改变我select一个孩子后,我正在寻找select框来改变高度。 所以,当页面第一次加载它说:“没有select的孩子”当你点击下拉,select一个孩子,你看到孩子的形象。 现在我需要select框来扩大! 否则,孩子的照片被切断。 有谁明白?

如何从DOM删除select2

假设我们有一个简单的select2列表: <select id="e1"> <option value="AL">Alabama</option> … <option value="WY">Wyoming</option> </select> 发起如下: $("#e1").select2(); 我如何删除select2并将其返回到正常的下拉菜单? 我找不到任何示例或文档中的条目。 就像是: $("#e1").select2('remove'); 会好的。

如何使用<input>从select2中获取选定的文本

我正在使用select2控件,通过ajax 加载数据 。 这需要使用<input type=hidden..>标签。 现在,我想要检索选定的文本。 ( data-bindexpression式中的value属性只有id ) 我已经尝试了$(".select2-chosen").text() ,但是当我在页面上有多个select2控件时,这个会中断。

通过jquery-select2从多值select框中获取选定的值?

我使用Select2 Jquery绑定我的下拉菜单,用于多选。 我正在使用select2的jQuery。 它工作正常,我可以绑定我的下拉列表,但我需要从我的多值select器中获取选定的值。 我正在寻找方法来获取select2 Jquery所支持的值。 它可能有一个函数获取选定的值。 我的下拉式绑定代码 $(".leaderMultiSelctdropdown").select2( { maximumSelectionSize: 4 });

select2强调页面加载

我正在尝试使一个select2框在页面加载时出现在其聚焦状态。 我已经尝试了以下内容: $('#id').select2('focus'); $('#id').trigger('click'); $('#id').trigger('focus'); 只有第一行似乎有任何效果,它会确定select2字段的焦点,但是它需要额外的按键来显示search字段,并允许inputsearchstring。 因此,如果你加载页面并开始键入:“search”,“S”将打开search框,然后其余的键将被input到它,所以你会search“earch”

使用jQuery Select2清除下拉菜单

我试图以编程方式清除使用梦幻般的Select2库下拉。 下拉菜单使用Select2 query选项dynamic填充远程ajax调用。 HTML: <input id="remote" type="hidden" data-placeholder="Choose Something" /> 使用Javascript: var $remote = $('#remote'); $remote.select2({ allowClear: true, minimumInputLength: 2, query: function(options){ $.ajax({ dataType: 'json', url: myURL + options.term, error: function(jqXHR, textStatus, errorThrown){ smoke.alert(textStatus + ": server returned error on parsing arguments starting with " + options.term); }, success: function(data, textStatus, jqXHR){ var results = […]

如何设置jquery select2的选定值?

这属于select2版本4之前的代码 我有一个简单的select2代码,可以从ajax获取数据 $("#programid").select2({ placeholder: "Select a Program", allowClear: true, minimumInputLength: 3, ajax: { url: "ajax.php", dataType: 'json', quietMillis: 200, data: function (term, page) { return { term: term, //search term flag: 'selectprogram', page: page // page number }; }, results: function (data) { return {results: data}; } }, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return […]

selectselect2后触发一个动作

我正在使用select2库进行search。 selectsearch结果后有什么办法可以触发一个动作吗? 例如打开一个popup窗口,或简单的js警报。 $("#e6").select2({ placeholder: "Enter an item id please", minimumInputLength: 1, ajax: { // instead of writing the function to execute the request we use Select2's convenient helper url: "index.php?r=sia/searchresults", dataType: 'jsonp', quietMillis: 3000, data: function (term, page) { return { q: term, // search term page_limit: 10, id: 10 }; }, results: function […]