checkbox 选中的id拼接长字符串

需求描述:为了做一个批量操作,需要获取到checkbox选中的项的id,并且把选中的id拼接成字符串。

解决思路:先获取到checkbox选中项,然后拼接。(这tm不废话么),问题的关键就是获取checkbox的选中项,废话就不多说了直接上代码

代码:

//html
<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="checkboxes" th:value="${xxx.xxxId}" value="id" name="id" /> <span></span>
</label>

//js
function enablBut(type,oper) {
    var selectIds;
$("input.checkboxes[name='id']:checkbox").each(function() {
if ($(this).is(":checked")) {
if (selectIds != "" && typeof (selectIds) != "undefined") {
selectIds += "," + $(this).val();
} else {
selectIds = $(this).val();
}
        
ableMany=true;
      }
    });
if (selectIds == "" || typeof (selectIds) == "undefined") {
layer.msg("请选择操作项!!");
return;
}
}

总结:每天记录一点点,ヾ(◍°∇°◍)ノ゙

posted @ 2018-09-10 16:23  ジ绯色月下ぎ  阅读(621)  评论(0编辑  收藏  举报