简体   繁体   English

修改占位符-jQuery Sumoselect-下拉列表

[英]Modify placeholder - Jquery Sumoselect - Dropdown

I'm using a plugin Jquery SumoSelect Multi Select in my application and I'm wondering how to switch the placeholder a select intance is reloaded. 我在我的应用程序中使用插件Jquery SumoSelect Multi Select,我想知道如何切换占位符,以重新加载选择实例。

I load new options via AJAX in a "select" instance but the placeholder remains the same that has been set at the beginning. 我通过AJAX在“选择”实例中加载新选项,但占位符与开始时设置的相同。

HTML Select HTML选择

<Select id = "c_ba" multiple = "multiple" disabled> </select>

INSTANCE INSTANCE

 $("#C_ba").SumoSelect ({
placeholder "Neighborhoods", //initial placeholder
okCancelInMulti: true,
selectAll: true
});

In another Select I recharge the select above: 在另一个“选择”中,我为上述选择充电:

$('#C_ci').Change(function (e) {
SelectValue var = $(this).val();

$ .ajax ({
type: 'GET'
url: 'rotinas.asp'
date: "action = carrega_bairros & cod_cidade = '+ SelectValue,
success: function (html) {

var str = html;
var arr = str.split ("###");
arraux var = new Array ();

var select = $("#c_ba"); //html select initial
var options = '';

select.css ({'display', 'none'});
select.empty ();

if (str! = '') {
for (var x = 0; x <arr.Length; x ++) {
arraux = arr [x] .Split ("...");
options + = "<option value = '" + arraux [0] + "'>" + arraux [1] + "</ option>";
}

select.append (options);
select [0] .sumo.enable (); // Enable the SUMO SELECT 
select [0] .sumo.reload (); // Reload With news options loads

// Here I would like to exchange the original placeholder "Neighborhoods" to the following placeholder (eg.): "Select the Neighborhoods"

} Else {
select [0] .sumo.disable ();
select [0] .sumo.reload ();
}
},

error: function (e) {
// Called When there is an error
console.log (e.Message);
}
});

According to the documentation of Sumoselect, maximum priority is given to native placeholder attribute in select tag. 根据Sumoselect的文档,在select标签中,本机占位符属性具有最高优先级。 So you can change the placeholder attribute of the select tag (using jQuery attr() method) before reloading sumoselect. 因此,您可以在重新加载sumoselect之前更改select标签的占位符属性(使用jQuery attr()方法)。

select.append(options);
select.attr("placeholder","Select the Neighborhoods");
select[0].sumo.enable();
select[0].sumo.reload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM