<span style="margin-left: 20px">
<label for="box">多选框</label>
<input type="checkbox" id="box" value="0">
</span>
<script>
var box = false;
var box_code = -1;
var msg = {};
$('#box').on('click', function () {
var obj = document.getElementById("box");
// var box = $('#box').get(0).checked;
// var box = $('#box').is(':checked');
var box = $('#box').attr('checked');
if (box == true) {
box_code = $('#box').val();
} else {
box_code = -1;
}
msg['code'] = box_code;
msg['status'] = box;
alert(JSON.stringify(msg))
})
</script>
<!DOCTYPE html>
<html lang="en">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<body>
<span style="margin-left: 20px">
<label for="box">多选框</label>
<input type="checkbox" id="box" value="0">
</span>
</body>
<script>
var box = false;
var box_code = -1;
var msg = {};
$('#box').on('click', function () {
var obj = document.getElementById("box");
// var box = $('#box').get(0).checked;
// var box = $('#box').is(':checked');
var box = $('#box').attr('checked');
if (box == true) {
box_code = $('#box').val();
} else {
box_code = -1;
}
msg['code'] = box_code;
msg['status'] = box;
alert(JSON.stringify(msg))
})
</script>
</html>
- 实现效果
