javascript - IE 无法在单选按钮上使用 "return false"

标签 javascript html internet-explorer-8 radio-button

我使用如下的 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/

相关文章:

javascript - Chrome 应用,在新标签页中打开链接

html - 如何使用 xpath 从 div 获取 href 值?

html - 网站上未显示字体(来自 Google Fonts)

performance - WatiN Dispose() 真的很慢

html - Google Web 字体在 IE8 中不工作

javascript - 从 Javascript 修改框架滚动

javascript - 从jsp获取id

html - 如何让按钮扩展 html 表头的长度?

java - 在 IE8 中按回车键会导致我的应用程序转到登录页面

javascript - 通过比较具有不同键值对的对象对 Javascript 数组进行排序