【发布时间】:2021-01-16 21:22:16
【问题描述】:
有两个(或更多)选择下拉列表,其中下拉值(选项值)由用户创建。问题是当用户在两个选择下拉列表中的任何一个中创建一些值时,两个选择应该具有相同的下拉值。下拉列表值应该相同,并加载到其他下拉列表值中,而不管它们在哪里创建(添加)。
参考链接:-https://selectize.github.io/selectize.js/
小提琴链接:- http://jsfiddle.net/1oy2d6e9/
html
<section class="demo" id="demo-single-item-select">
<div class="header">
Single Item Select
</div>
<div class="sandbox">
<label for="select-beast">Beast:</label>
<select id="select-beast" class="demo-default" placeholder="create a person by typing...">
</select>
</div>
<div class="sandbox">
<label for="select-beast">Beast2:</label>
<select id="select-beast2" class="demo-default" placeholder="create a person by typing...">
</select>
</div>
<div class="description">
These two select box have same values when values are created in either of the two.
<a href="https://selectize.github.io/selectize.js/">https://selectize.github.io/selectize.js/</a>
</div>
</section>
js
var gArr = [];
// selectize should load all dropdown values ie in gArr initially;
$('#select-beast2').selectize({
create: true,
sortField: 'text',
searchField: 'item',
create: function(input) {
gArr.push(input); //<=======storing in global variable
return {
value: input,
text: input
}
}
});
$('#select-beast').selectize({
create: true,
sortField: 'text',
searchField: 'item',
create: function(input) {
gArr.push(input); //<=======storing in global variable
return {
value: input,
text: input
}
}
});
【问题讨论】:
标签: javascript jquery selectize.js