JSFiddle - React, Tailwind, and code Playground
HTML
<p>2つ以上を選ぶとエラーが表示</p>
<br/>
<input type="checkbox" name="tech" value="List 01" /> List 01
<br/>
<input type="checkbox" name="tech" value="List 02" /> List 02
<br/>
<input type="checkbox" name="tech" value="List 03" /> List 03
<br/>
<input type="checkbox" name="tech" value="List 04" /> List 04
<br/>
<input type="checkbox" name="tech" value="List 05" /> List 05
<br/>
CSS
body {
font-size : 12pt;
padding :10px;
}
JavaScript
$(document).ready(function () {
$("input[name='tech']").change(function () {
var maxAllowed = 2;
var cnt = $("input[name='tech']:checked").length;
if (cnt > maxAllowed) {
$(this).prop("checked", "");
alert('' + maxAllowed + 'つ以上は選べません!');
}
});
});