Dies funktioniert in allen Versionen von Jquery.
//-- Check if there's no checked radio button
if ($('#radio_button').is(':checked') === false ) {
//-- if none, Do something here
}
Um eine Funktion zu aktivieren, wenn ein bestimmtes Optionsfeld markiert ist.
// get it from your form or parent id
if ($('#your_form').find('[name="radio_name"]').is(':checked') === false ) {
$('#your_form').find('[name="radio_name"]').filter('[value=' + checked_value + ']').prop('checked', true);
}
Ihr html
$('document').ready(function() {
var checked_value = 'checked';
if($("#your_form").find('[name="radio_name"]').is(":checked") === false) {
$("#your_form")
.find('[name="radio_name"]')
.filter("[value=" + checked_value + "]")
.prop("checked", true);
}
}
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="" id="your_form">
<input id="user" name="radio_name" type="radio" value="checked">
<label for="user">user</label>
<input id="admin" name="radio_name" type="radio" value="not_this_one">
<label for="admin">Admin</label>
</form>