我UI
在更改时有一个选择字段,我正在填充 div 中有相应的数据,其中有ul
和li
,现在我要做的是list
有复选框on
,of
所以无论用户选择什么并单击按钮,我都想转换它成一个数组对象
我做了什么
$(document).ready(function() {
$("#btn-search").hide();
var Data = {
"India A": [
"Mumbai",
"Delhi",
"Kolkata"
],
"India B": [
"Bangalore",
"Chennai"
]
}
var CountersName = Object.keys(Data)
let dropdown = $("#counterNames")
dropdown.append('<option selected="true" disabled>Select Counter</option>');
for (var i = 0; i < CountersName.length; i++) {
$('<option/>').val(CountersName[i]).html(CountersName[i]).appendTo('#counterNames');
}
$("#counterNames").on('change', function() {
$(".card").show();
$("#btn-search").show();
var value = $(this).val();
$(".card-header").text(value);
// console.log(Data[value]);
var ul = document.getElementById(".list-group");
ul_innerhtml = "";
for (i = 0; i < Data[value].length; i++) {
title = Data[value][i];
var ul_innerhtml = ul_innerhtml + '<li class="list-group-item">' + title + '<label class="switch "><input type="checkbox" class="success"><span class="slider round"> </span></label></li>';
}
$(".list-group").html(ul_innerhtml);
})
});
$("button").click(function() {
var selected = new Array(); // here I am trying to do
$("input:checkbox[name=type]:checked").each(function() {
selected.push($(this).val());
});
console.log(selected)
当用户点击一下按钮,我想要检索的选择选项被选中,然后检查在这样{India A:["Mumbai","Delhi","Kolkata"]}
的时候India A
选择的是,我试图让它进入阵列第一,但该数值显示为空
相关分类