回答編集履歴
1
chousei
test
CHANGED
@@ -1 +1,29 @@
|
|
1
|
+
# 参考
|
1
2
|
ラジオボタンで当該箇所のdisabledも付け外しすればよいでしょう
|
3
|
+
HTML要素の特定の仕方は色々あると思うので一例です
|
4
|
+
```javascript
|
5
|
+
<script>
|
6
|
+
const s='[name="data[Contact][contact_kind]"]';
|
7
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
8
|
+
if(document.querySelectorAll(`${s}:checked`).length==0){
|
9
|
+
document.querySelector(`${s}`).checked=true;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
document.addEventListener('change',()=>{
|
13
|
+
const idx=[...document.querySelectorAll(s)].indexOf(document.querySelector(`${s}:checked`));
|
14
|
+
document.querySelectorAll('.zen_han').forEach((x,y)=>{
|
15
|
+
x.disabled=idx!==y;
|
16
|
+
});
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
<input type="radio" name="data[Contact][contact_kind]" id="ContactContactKind1" class="contact_method inquiryRadio" value="1" />
|
20
|
+
<label for="ContactContactKind1">メール</label>
|
21
|
+
<input type="radio" name="data[Contact][contact_kind]" id="ContactContactKind2" class="contact_method inquiryRadio" value="2" />
|
22
|
+
<label for="ContactContactKind2">電話</label>
|
23
|
+
|
24
|
+
メールアドレス
|
25
|
+
<input name="data[Contact][email]" type="text" class="input zen_han" placeholder="例 example@example.jp" maxlength="200" id="ContactEmail" />
|
26
|
+
|
27
|
+
電話番号
|
28
|
+
<input name="data[Contact][phone]" type="text" class="input zen_han" placeholder="例 09012345678" maxlength="200" id="ContactPhone" />
|
29
|
+
```
|