简体   繁体   中英

IE can't use “return false” on radio button

I use js like below to prevent click on some radio button.

It's work totally fine in Chrome.

But on IE8 It's still can't check but default value was disappear when click other radio in group.

 $("body").on("change", ".readonly", function () {
    return false;
});

How can i make radio readonly and also work on IE8?

<input type="radio" readonly /> does not work, but using click does partly work. If you have two radios with the same name, IE will however still uncheck the checked one regardless with this code

 $("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" /> 


Here is a solution: 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" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM