У меня есть три флажка: приостановлено, вариант 1 и вариант 2
Используя приведенный ниже код, установите флажок «Приостановлено», остальные два отключаются. Если я сниму флажок «Приостановлено», они станут доступны (отключенный атрибут удален).
Я хотел бы применить ту же логику при загрузке страницы. Мой код ниже:
Код: Выделить всё
(function( $ ) {
'use strict';
$( document ).ready(function() {
if( $('input[name="suspended"]').is(':checked')){
console.log( "Suspended is checked" );
$('input[name="option1"]' ).attr("disabled", true);
$('input[name="option2"]' ).attr("disabled", true);
}
else{
console.log( "Suspended is unchecked" );
$('input[name="option1"]' ).removeAttr("disabled");
$('input[name="option2"]' ).removeAttr("disabled");
}
$( 'input[name="suspended"]' ).change( function( e ){
e.preventDefault;
if ($(this).is(':checked')) {
$('input[name="option1"]' ).attr("disabled", true);
$('input[name="option2"]' ).attr("disabled", true);
}else {
$('input[name="option1"]' ).removeAttr("disabled");
$('input[name="option2"]' ).removeAttr("disabled");
}option2
} );
});
})( jQuery );
Подробнее здесь: https://stackoverflow.com/questions/783 ... ing-jquery
Мобильная версия