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");
}
}
}