我使用如下的 js 来防止点击某些单选按钮。
它在 Chrome 中工作得很好。
但在 IE8 上它仍然无法检查,但当单击组中的其他 radio 时,默认值消失。
$("body").on("change", ".readonly", function () {
return false;
});
我怎样才能使 radio 只读并在 IE8 上工作?
最佳答案
<input type="radio" readonly />
不起作用,但使用点击确实部分起作用。如果您有两个同名的 radio ,IE 仍然会取消选中已选中的 radio ,无论使用此代码如何
$("body").on("click", ".readonly", function(e) {
e.preventDefault();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input name="rad" type="radio" class="readonly" />
<input name="rad" type="radio" checked class="readonly" />
这是一个解决方案:https://stackoverflow.com/a/5437904/295783
$(function() {
$(':radio:not(:checked)').attr('disabled', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input name="rad" type="radio" class="readonly" />
<input name="rad" type="radio" checked class="readonly" />
关于javascript - IE 无法在单选按钮上使用 "return false",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31132937/