teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

そーす

2016/10/26 15:57

投稿

hiim
hiim

スコア1689

answer CHANGED
@@ -1,2 +1,15 @@
1
1
  カスタム属性を使えば可能ではありますね。
2
- http://dresscording.com/blog/html5/custom_data_attribute.html
2
+ http://dresscording.com/blog/html5/custom_data_attribute.html
3
+
4
+ ```html
5
+ <input type="checkbox" name="mobile" data-name="android" value = "500">android
6
+ <input type="checkbox" name="mobile" data-name="iphone" value = "800">iphone
7
+ ```
8
+ ```javascript
9
+ var selected = [];
10
+ for (var i = 0; i < mobiles.length; i++) {
11
+     if (mobiles[i].checked) {
12
+     selected.push(parseInt(mobiles[i].value));
13
+     console.log(mobiles[i].getAttribute('data-name'));
14
+ }
15
+ ```