Foxtable(狐表)用户栏目专家坐堂 → 请问在weui 內的复选列表项中如何限制选择的数目?


  共有1371人关注过本帖树形打印复制链接

主题:请问在weui 內的复选列表项中如何限制选择的数目?

帅哥哟,离线,有人找我吗?
kennypalm
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:275 积分:3241 威望:0 精华:0 注册:2017/10/4 1:48:00
请问在weui 內的复选列表项中如何限制选择的数目?  发帖心情 Post By:2023/10/11 22:13:00 [只看该作者]

请问在weui 內的复选列表项中如何限制选择的数目? 比如列表中有 10 项只能选 2 项 如何实现这个功能 ?

图片点击可在新窗口打开查看此主题相关图片如下:sp20231011_215004.jpg
图片点击可在新窗口打开查看


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2023/10/12 10:10:00 [只看该作者]

httprequest

Dim wb As New weui
wb.AddForm("", "form1", "test.htm")
With wb.AddCheckGroup("form1", "rdg1", "浏览器")
    .Add("bw1", "Intenet Explorer").Attribute = "onclick=""setChecked(this)"""
    .Add("bw2", "Google Chorme").Attribute = "onclick=""setChecked(this)"""
    .Add("bw3", "FireFox").Attribute = "onclick=""setChecked(this)"""
    .Add("bw4", "Safari").Attribute = "onclick=""setChecked(this)"""
End With
With wb.AddButtonGroup("form1", "btg1", True)
    .Add("btn1", "确定", "submit")
End With

wb.AppendHTML("<script src='test.js' ></script>")
e.WriteString(wb.Build)

test.js文件
var checkValues = [];
function setChecked(e) {
    if (e.checked) {
        if (checkValues.length == 2) {
            e.checked = false;
            return;
        }
        else {
            checkValues.push(e.id);
            if (checkValues.length == 2) {
                for (let i = 1; i <= 4; i++) {
                    let rd = document.getElementById('bw' + i);
                    if (checkValues.indexOf('bw' + i) == -1)
                        rd.setAttribute("disabled", true);
                    else
                        rd.removeAttribute("disabled");
                }
            }
        }
    }
    else {
        checkValues.splice(checkValues.indexOf(e.id), 1);
        for (let i = 1; i <= 4; i++) {
            let rd = document.getElementById('bw' + i);
                rd.removeAttribute("disabled");
        }
    }
}
[此贴子已经被作者于2023/10/12 10:10:29编辑过]

 回到顶部