我试图让单选按钮列表显示为复选框列表,但具有单选按钮列表的好处(即只能提交1个值)。
然而,我遇到的问题是,在Google Chrome中,默认值设置为“不确定”'虽然它应该设置为' false'。列表的第一个值应该是' true'默认情况下,目前有效。
如何防止第二个值设置为不确定?
代码有时会表现得很奇怪,因为刷新浏览器有时会导致取消检查不确定性,有时会将其检查回来以确定不确定性。
我还没有找到一种模式。
$(document).ready(function() {
$("input[type=radio]:eq(0)").prop("checked", true);
$("input[type=radio]:eq(0)").data("ischecked", true);
$("input[type=radio]:eq(1)").prop("checked", false);
$("input[type=radio]:eq(1)").addClass("opt-in-radio");
$('form').on('click', ':radio', function() {
var status = $(this).data('ischecked'); //get status
status && $(this).prop("checked", false); //uncheck if checked
$(this).data('ischecked', !status); //toggle status
if (this.className == "opt-in-radio") $("input[type=radio]:eq(0)").prop("checked", !this.checked)
});
});

input[type="radio"] {
-moz-appearance: checkbox;
-webkit-appearance: checkbox;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;