-
-
Save codingwithsara/8b370c2f29ed89e55904e561f6b5a1c2 to your computer and use it in GitHub Desktop.
JS Checkboxes 3
This file contains 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> | |
<html lang="ja"> | |
<head> | |
<!-- 省略 --> | |
</head> | |
<body> | |
<div class="container"> | |
<input type="checkbox" class="checks" value="あいうえお"> あ____<br> | |
<input type="checkbox" class="checks" value="かきくけこ"> か_____<br> | |
<input type="checkbox" class="checks" value="さしすせそ"> さ_____<br> | |
<button onclick="getValue()">値を取得</button> | |
</div> | |
<script> | |
function getValue() { | |
var checks = document.getElementsByClassName('checks'); | |
var str = ''; | |
for ( i = 0; i < 3; i++) { | |
if ( checks[i].checked === true ) { | |
str += checks[i].value + " "; | |
} | |
} | |
alert(str); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment