Last active
August 29, 2015 13:58
-
-
Save RyoSugimoto/10110827 to your computer and use it in GitHub Desktop.
ラジオボタンやチェックボックスが「checked」状態であるか調べる。
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
function isChecked (name) { | |
if (name instanceof Array) { | |
for (var i = name.length; 0 < i--;) { | |
if (!isChecked(name[i])) { | |
return false; | |
} | |
} | |
return true; | |
} else if (typeof name === 'string') { | |
var radios = document.getElementsByName(name); | |
for (var j = radios.length; 0 < j--;) { | |
if (radios[j].checked) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment