我正在使用 jquery choose 插件,该插件在页面加载时使用两个输入框......并且需要像本例中那样,当我在第一个框中选择数字 1 时,该数字已从第二个输入框中删除......这个工作正常...但问题是当我添加动态输入框时,我无法从添加的动态输入框中删除元素编号 1。
所以问题是:当选择其他动态添加的输入框并且每个选择框中的所选元素在所有存在和动态添加的选定框中不可见时,如何从输入框中删除选定的值?
这是 jsfiddle:
[http://jsfiddle.net/dq97z/640/][1]
这是我需要的图片:
最佳答案
也许这对你有帮助
http://jsfiddle.net/s9r73qjm/
//an array to save selections
var selectedVals = [];
//push to the array when we have selected
selectedVals.push(selectedValue);
//check on the values when building the drop down
$( "#btn_newrow" ).click(function() {
var newList = document.createElement("select");
newList.dataset.placeholder = "Number row 3";
newList.style.width = "350px";
var newListData = new Option("placeholder", "placeholder");
for (var i = 0; i < 6; i++){
if (selectedVals.indexOf(i.toString()) == -1){
//then it hasn't been selected
newListData = new Option(i.toString(), i.toString());
newList.appendChild(newListData);
}
$( ".wrapper" ).append(newList);
}
});
关于javascript - jQuery Chose插件如何从下拉列表中删除所选元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41945008/