通用复选框

编程入门 行业动态 更新时间:2024-10-09 03:22:47

通用<a href=https://www.elefans.com/category/jswz/34/1768610.html style=复选框"/>

通用复选框

  1. 渲染复选框
select = `<div style="display: inline-block;" class="dictionary_check_box multipleChoiceBox"><label>${this._dictionaryCheck[i]}:</label><div style="position: relative;float: right;" class="_productTypeBox"><div style="position: relative;width: 120px;" class="_inputBox"><i class="icon-input" style="background: url(assets/images/oa/下拉.png) no-repeat;position: absolute;right: 9px;top: 10px;width: 10px;height: 10px;background-size: contain;"></i><input name='${_label[0]}' id="_dictionaryCheck${i}" class="_selectInfo form-control input-sm input-v5" style="background: #fff;width: 120px;"type="text" value="" title="" readonly autocomplete="off"placeholder='请选择${this._dictionaryCheck[i]}'/></div><div class="_pickProType dropdown-menu wkt-scroll"style="padding: 5px 10px;max-height: 200px;overflow-y: auto;min-width: 120px;"><ul></ul></div></div></div>`//获取复选框所有元素this.getCheckData() 
  1. 渲染复选框内所有元素
	//获取Dictionary复选框数据getCheckData: async function () {const res = await request(url,query: {},cacheBust: true)let { getMe, say } = res.dataif (say.errMsg == '' && say.statusCode == '0000') {getMe.forEach(function (item) {item = item.replace(/[^0-9]/gi, "");});getMe.sort(compare());function compare() {return function (a, b) {var value1 = a.split(" ")[0];var value2 = b.split(" ")[0];return value1 - value2;};}getMe = Array.from(new Set(getMe));let content = `<li class="inputS single" style="white-space: nowrap;display: flex;align-items: center;"><input type="checkbox" style="margin-top:0px;" eleName="全选"><label for="checkAll"><span title="全选">全选</span></label></li> `for (let j = 0; j < getMe.length; j++) {if (getMe[j].trim() == "") {getMe.splice(j, 1);} else {content += `<li class="inputS single" style="white-space: nowrap;display: flex;align-items: center;"><input type="checkbox" style="margin-top:0px;" eleName="${getMe[j]}"><label for="${getMe[j]}"><span title="${getMe[j]}">${getMe[j]}</span></label></li>`}}this.$el.find('.dictionary_check_box ._pickProType ul').eq(i).append(content)} else {msgUtils.warning(`获取${this._dictionaryCheck[i]}失败!`)}},
  1. 绑定复选框的一些相关事件
	//显示复选框showMultiselectBox: function (e) {e.stopPropagation();let that = this;let hideBoxNum = that.$el.find("._pickProType").length;for (let i = 0; i < hideBoxNum; i++) {that.$el.find("._pickProType").eq(i).hide();}$(e.currentTarget).parent().find("._pickProType").show();},//隐藏复选框hideMultiselectBox: function (e) {let that = this;let hideBoxNum = that.$el.find("._pickProType").length;for (let i = 0; i < hideBoxNum; i++) {let pop = $("._pickProType").eq(i);if (!pop.is(e.target) && pop.has(e.target).length === 0) {that.$el.find("._pickProType").eq(i).hide();}}},//复选框勾选事件checkMultiselect: function (e) {e.stopPropagation()const nowEleName = $(e.currentTarget).attr("eleName");const checkStatus = !!$(e.currentTarget).prop("checked");const $Content = $(e.currentTarget).parents("._productTypeBox").find("input._selectInfo[type='text']")const $SelectList = $(e.currentTarget).parents("._pickProType").find(".inputS input")let allData = []$SelectList.each(function () {allData.push($(this).attr('eleName'))});allData.shift()  //去除 '全部' 元素if (nowEleName === "全选") {let inputVal = "";if (checkStatus) {allData.forEach((str, i) => {inputVal += str;i !== allData.length - 1 && (inputVal += ",");})}$Content.val(inputVal)$SelectList.each(function (index, element) {element.checked = checkStatus})} else {let getInput = $Content.val()if (checkStatus) {let newValue = getInput ? `${getInput},${nowEleName}` : nowEleName;$Content.val(newValue)} else {let arr = getInput.split(",");arr.splice(arr.findIndex((v) => v == nowEleName),1);$Content.val(arr.join(","))}}this.queryData()},

更多推荐

通用复选框

本文发布于:2024-03-12 10:04:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1731268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!