Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created June 7, 2011 09:01
Show Gist options
  • Save cognitom/1011927 to your computer and use it in GitHub Desktop.
Save cognitom/1011927 to your computer and use it in GitHub Desktop.
jQueryで、選択済みチェックボックスの値のリストを取得するワンライナー
//<input type="checkbox" name="sample[]" value="1" checked="checked" />
//<input type="checkbox" name="sample[]" value="2" />
//<input type="checkbox" name="sample[]" value="3" checked="checked" />
var str = $('input:checkbox[name="sample[]"]:checked').map(function(i){ return this.value }).get().join(', ');
alert(str);//1, 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment