質問編集履歴
4
修正しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
// $('#button a').click(
|
|
107
107
|
// function(){
|
|
108
108
|
// if(checkForm()){
|
|
109
|
-
// $("#
|
|
109
|
+
// $("#form").submit()
|
|
110
110
|
// }});
|
|
111
111
|
|
|
112
112
|
$(function(){
|
3
現在の状況を追記しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -73,4 +73,73 @@
|
|
|
73
73
|
チェックボックスのやり方はたくさん出てくるのにラジオボタンについてはほとんど指南サイトが出て来ず困っています。
|
|
74
74
|
当方、つい昨日[let][const]を学んだくらいの知識量しか持っていません、わかりやすく教えていただけるととても助かります。
|
|
75
75
|
|
|
76
|
-
どうぞよろしくお願いいたします。
|
|
76
|
+
どうぞよろしくお願いいたします。
|
|
77
|
+
|
|
78
|
+
教えていただいた文をコピペさせていただき、現在はこのような状態になっています。
|
|
79
|
+
|
|
80
|
+
HTML
|
|
81
|
+
```
|
|
82
|
+
<table id="formtable">
|
|
83
|
+
<form id="form" enctype="multipart/form-data" onsubmit="return checkSubmit();">
|
|
84
|
+
<tr>
|
|
85
|
+
<th class="f_th">投稿 <span class="req">必須</span></th>
|
|
86
|
+
<td class="f_td">
|
|
87
|
+
<p>質問/p>
|
|
88
|
+
<input type="radio" name="radio" value="はい" id="yes_"><label for="yes_" class="label"> はい</label>
|
|
89
|
+
<input type="radio" name="radio" value="いいえ" id="no_"><label for="no_" class="label"> いいえ</label>
|
|
90
|
+
<div id="return_a"></div>
|
|
91
|
+
<!--<label for="yes_" class="label"><input type="radio" name="radio" value="はい">はい</label><br>
|
|
92
|
+
<label for="no_" class="label"><input type="radio" name="radio" value="いいえ">いいえ</label><br>-->
|
|
93
|
+
</td>
|
|
94
|
+
</tr>
|
|
95
|
+
<!-- <input type="button" name="button" id="button" value="送信する" onclick="return checkForm();">-->
|
|
96
|
+
<!--<div id="button"><p class="line_m">送信する</p></div>-->
|
|
97
|
+
<div id="button"><a href="javascript:void(0);">送信する</a></div>
|
|
98
|
+
<!-- <div id="button"><a href="#">投稿</a></div>
|
|
99
|
+
--> </div>
|
|
100
|
+
</form>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
JS
|
|
104
|
+
```
|
|
105
|
+
//$(function(){
|
|
106
|
+
// $('#button a').click(
|
|
107
|
+
// function(){
|
|
108
|
+
// if(checkForm()){
|
|
109
|
+
// $("#totekeroForm").submit()
|
|
110
|
+
// }});
|
|
111
|
+
|
|
112
|
+
$(function(){
|
|
113
|
+
$('#button a').on('click',function(e){
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
if($('[name=radio]:radio:checked').length>0){
|
|
116
|
+
$('#form').trigger('submit');
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
$.validator.addMethod(
|
|
120
|
+
"regex",
|
|
121
|
+
function(value, element, regexp) {
|
|
122
|
+
var re = new RegExp(regexp);
|
|
123
|
+
return this.optional(element) || re.test(value);
|
|
124
|
+
},
|
|
125
|
+
"Please check your input."
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
$("#form").validate({
|
|
129
|
+
rules : {
|
|
130
|
+
radio: {required: true}
|
|
131
|
+
},
|
|
132
|
+
messages: {
|
|
133
|
+
radio : { required : "選択してください" }
|
|
134
|
+
},
|
|
135
|
+
errorPlacement: function(error, element) {
|
|
136
|
+
if(element.is(':radio'))
|
|
137
|
+
{
|
|
138
|
+
error.appendTo(element.parent());
|
|
139
|
+
}
|
|
140
|
+
else{
|
|
141
|
+
error.insertAfter(element);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
```
|
2
HTMLのID return_aについて追記しました。送信ボタンの記述を追加
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
</td>
|
|
20
20
|
</tr>
|
|
21
21
|
</table>
|
|
22
|
+
<div id="button"><a href="javascript:void(0);">送信</a></div>
|
|
23
|
+
|
|
22
24
|
```
|
|
23
25
|
JSは
|
|
24
26
|
```$(function(){
|
|
@@ -66,6 +68,8 @@
|
|
|
66
68
|
|
|
67
69
|
以上になります。
|
|
68
70
|
|
|
71
|
+
※<div id="return_a"></div>はエラー文が出る場所として作成
|
|
72
|
+
|
|
69
73
|
チェックボックスのやり方はたくさん出てくるのにラジオボタンについてはほとんど指南サイトが出て来ず困っています。
|
|
70
74
|
当方、つい昨日[let][const]を学んだくらいの知識量しか持っていません、わかりやすく教えていただけるととても助かります。
|
|
71
75
|
|
1
JQUERYのリンクを追加しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
チェックしないとエラー文が出るラジオボタンを設置したいのですが、うまく動いてくれません。
|
|
3
3
|
|
|
4
4
|
jquery.validate.jsのバージョンは1.9.0を使っています。
|
|
5
|
+
[https://github.com/jquery-validation/jquery-validation/releases/tag/1.9.0
|
|
6
|
+
](https://github.com/jquery-validation/jquery-validation/releases/tag/1.9.0http://)
|
|
5
7
|
|
|
6
8
|
HTMLは
|
|
7
9
|
```
|