質問編集履歴
1
コード追記
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -2,9 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
次のようなイメージですが、さっぱり動いてくれません。
|
|
4
4
|
[https://jsfiddle.net/vL5Lmmtc/](https://jsfiddle.net/vL5Lmmtc/)
|
|
5
|
+
```html
|
|
6
|
+
<select class="select_color" name="onamae" data-required="no" data-type="select">
|
|
7
|
+
<option value="blue">ブルー</option>
|
|
8
|
+
<option value="red">レッド</option>
|
|
9
|
+
<option value="green">グリーン</option>
|
|
10
|
+
</select>
|
|
11
|
+
<div class="change">色よ変われ!</div>
|
|
12
|
+
```
|
|
5
13
|
|
|
14
|
+
```javascript
|
|
15
|
+
<sctipt>
|
|
16
|
+
$('select').change(function(){
|
|
17
|
+
var num = document.onamae.selectedIndex;
|
|
18
|
+
var str = document.onamae.options[num].value;
|
|
19
|
+
document.getElementsByClassName("change")[0].css('background','str')
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
```
|
|
23
|
+
|
|
6
|
-
または
|
|
24
|
+
または下記のように書けば1回は変更できるのですけれど、それじゃダメなのです。
|
|
7
25
|
[https://jsfiddle.net/23fgea8L/](https://jsfiddle.net/23fgea8L/)
|
|
26
|
+
```javascript
|
|
27
|
+
<sctipt>
|
|
28
|
+
$('select').change(function(){
|
|
29
|
+
$(".change").css('background-color','#f00')
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
```
|
|
8
33
|
|
|
9
34
|
お詳しい方、ご教示頂けませんでしょうか。。
|
|
10
35
|
宜しくお願い致します。
|