Показать сообщение отдельно
  #1 (permalink)  
Старый 25.03.2021, 14:40
Кандидат Javascript-наук
Отправить личное сообщение для fori Посмотреть профиль Найти все сообщения от fori
 
Регистрация: 27.01.2021
Сообщений: 117

Почему добавление класса работатет а проверка на checked нет
Здраствуйте, етот код создает красивый ефект выплывания underscore для кнопки
<!DOCTYPE html>

<head>
	<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
</head>

<body>
	<label class="signup-inactive"><input type="radio" class="btn" />Sign up</label>
	<script>$(function () {
			$(".btn").click(function () {
				$(".signup-inactive").toggleClass("signup-active");
			});
		});</script>
</body>
<style>
	.btn {
		cursor: pointer;
		text-decoration: none;
		transition: all 0.25s ease;
		color:red;
	}

	.signup-active {
		border-bottom: solid 2px #1059ff;
		padding-bottom: 10px;
		transition: all 0.25s ease;
	}

	.signup-inactive {
		text-decoration: none;
		transition: all 0.25s ease;
	}
</style>
</html>

Но можно ли сделать просто input type="radio" и проверять на checked без js? К примеру етот код не работает
<!DOCTYPE html>

<body>
	<label class="signup-inactive"><input type="radio" class="btn" />Sign up</label>
</body>
<style>
	.btn {
		cursor: pointer;
		text-decoration: none;
		transition: all 0.25s ease;
		color: red;
	}

	.btn:checked {
		border-bottom: solid 2px #1059ff;
		padding-bottom: 10px;
		transition: all 0.25s ease;
	}
</style>

</html>

Как ето можно исправить
Ответить с цитированием