Last active
December 16, 2015 20:39
-
-
Save froop/5493920 to your computer and use it in GitHub Desktop.
[jQuery] チェックボックスへの attr("checked", x) が1回目しか効かなくて数時間悩んだ。なぜか <!DOCTYPE html> を消すと直る。
結局、attr() を prop() に変えたら問題なくなった。 val([x]) でも OK。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="UTF-8" /> | |
</head> | |
<body> | |
<div> | |
<input name="check1" type="checkbox" value="on"> | |
<button id="check-on">on</button> | |
<button id="check-off">off</button> | |
</div> | |
<script src="jquery.js"></script> | |
<script> | |
$("#check-on").on("click", function () { | |
$("input[name=check1]").attr("checked", true); | |
}) | |
$("#check-off").on("click", function () { | |
$("input[name=check1]").removeAttr("checked"); | |
}) | |
</script> | |
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="UTF-8" /> | |
</head> | |
<body> | |
<div> | |
<input name="check1" type="checkbox" value="on"> | |
<button id="check-on">on</button> | |
<button id="check-off">off</button> | |
</div> | |
<script src="jquery.js"></script> | |
<script> | |
$("#check-on").on("click", function () { | |
$("input[name=check1]").prop("checked", true); | |
// $("input[name=check1]").val(["on"]); | |
// $("input[name=check1]").get(0).checked = true; | |
}) | |
$("#check-off").on("click", function () { | |
$("input[name=check1]").prop("checked", false); | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment