averainy's Blog

averainy

14 Jul 2023

Use Checkbox to Simulate Radio

复选框checkbox模拟单选框代码。


<html>
	<head>
      <script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script>
		<script>
			$(document).ready(function() {
    $("input[name^='a']").on("click", function() {
        $("input[name^='a']").not(this).prop("checked", false);
    });
});
		</script>
	</head>
	<body>
		<input type="checkbox" name="a1234" value="1">
		a1234
		</input>
		<input type="checkbox" name="a1235" value="1">
		a1235
		</input>
	</body>

</html>