質問編集履歴
1
コード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,11 +6,61 @@
|
|
6
6
|
|
7
7
|
[https://jsfiddle.net/vL5Lmmtc/](https://jsfiddle.net/vL5Lmmtc/)
|
8
8
|
|
9
|
+
```html
|
10
|
+
|
11
|
+
<select class="select_color" name="onamae" data-required="no" data-type="select">
|
12
|
+
|
13
|
+
<option value="blue">ブルー</option>
|
14
|
+
|
15
|
+
<option value="red">レッド</option>
|
16
|
+
|
17
|
+
<option value="green">グリーン</option>
|
18
|
+
|
19
|
+
</select>
|
20
|
+
|
21
|
+
<div class="change">色よ変われ!</div>
|
22
|
+
|
23
|
+
```
|
9
24
|
|
10
25
|
|
26
|
+
|
27
|
+
```javascript
|
28
|
+
|
29
|
+
<sctipt>
|
30
|
+
|
31
|
+
$('select').change(function(){
|
32
|
+
|
33
|
+
var num = document.onamae.selectedIndex;
|
34
|
+
|
35
|
+
var str = document.onamae.options[num].value;
|
36
|
+
|
37
|
+
document.getElementsByClassName("change")[0].css('background','str')
|
38
|
+
|
39
|
+
});
|
40
|
+
|
41
|
+
</script>
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
|
11
|
-
または
|
47
|
+
または下記のように書けば1回は変更できるのですけれど、それじゃダメなのです。
|
12
48
|
|
13
49
|
[https://jsfiddle.net/23fgea8L/](https://jsfiddle.net/23fgea8L/)
|
50
|
+
|
51
|
+
```javascript
|
52
|
+
|
53
|
+
<sctipt>
|
54
|
+
|
55
|
+
$('select').change(function(){
|
56
|
+
|
57
|
+
$(".change").css('background-color','#f00')
|
58
|
+
|
59
|
+
});
|
60
|
+
|
61
|
+
</script>
|
62
|
+
|
63
|
+
```
|
14
64
|
|
15
65
|
|
16
66
|
|