checkbox 界面数据循环、监听
var getDeviceInfo = ctx + "/url..."
$.get(getDeviceInfo, (e) => {
var carList = JSON.parse(e).deviceInfo
for (let i = 0; i < carList.length; i++) {
var optionStr = "<label style='margin: 3px 6px;padding: 2px;' className='check-box'><input type='checkbox' value='"
+ carList[i].selectValue + "' οnclick='checkChangeO()'>" + carList[i].selectLabel + "</label>"
$("#deviceCheck").append(optionStr)
}
$('#device').val(carList[0]?.selectValue)
checkChangeO()
})
function checkChangeO() {
$("#deviceCheck input[type=checkbox]").click(function () {
var cks = $("#deviceCheck :checked");
var leng = cks.length;
var arr = [];
cks.each(function (k, v) {
arr[arr.length] = $(v).val();
});
var needDeviceIds = arr.join(",");
console.log(needDeviceIds,"选中的设备id")
$("#device").val(needDeviceIds)
})
}
select 界面数据循环、监听
var getUnitsInfo = ctx + "/oa/getInfo/dept"
$.get(getUnitsInfo, (e) => {
var carList = JSON.parse(e).deptInfo
for (let i = 0; i < carList.length; i++) {
var optionStr = "<option value='" + carList[i].selectValue + "'>" + carList[i].selectLabel + "</option>"
$("#unitsSelect").append(optionStr)
}
$('#units').val(carList[0]?.selectValue)
})
$('#unitsSelect').on('change', (e) => {
var select = $('#unitsSelect option:selected')
console.log(select.text(), select.val())
$("#units").val(select.val())
})
|