下記コードの$('input[name = bbs]').on('click',function()から処理で、bbsをclickした時に変数myidでradioのidを取得、変数sendlistでr1~3をcheckした時の判別、if文でbbsがcheckedされたらtrueとなってsendlist[myid].textを含めたvalue値をsendに代入、chkid[]はsendlist[myid]のcheckflgがtrueか否かでdisabled
という様に解釈してるんですが、var myid = $(this).prop('id');の箇所で現段階だとid="r1"しか取得できていない状態で、複数のID属性の内「radioの、このID属性」と特定するコーディングを行いたいのですが、どの様なものなんでしょうか
<script type="text/javascript"> $(function() { $('form').on('submit',function() { if ($('#r1').prop('checked')) { with($('#name')) { if (val().length >= 10) { window.alert("ERROR1"); return false; } if (val() === "") { window.alert("ERROR2"); return false; } } with($('#comment')) { if (val().length >= 300) { window.alert("ERROR3"); return false; } if (val() === "") { window.alert("ERROR4"); return false; } } } if ($('#r2').prop('checked') || $('#r3').prop('checked')) { if ($('input[name = "chkid[]"]:checked').length == 0) { window.alert("ERROR5"); return false; } } return true; }); $('input[name = bbs]').on('click',function() { var myid = $(this).prop('id'); var sendlist = { "r1":{"text":"投稿",checkflg:true}, "r2":{"text":"更新",checkflg:false}, "r3":{"text":"削除",checkflg:false}, }; if ($('input[name = bbs]').prop('checked') == true) { $('#send').val(sendlist[myid].text); $('input[name = "chkid[]"]').prop('disabled',sendlist[myid].checkflg); } }); }); </script> </head> <body> <form method="post" action=""> <table> <tr> <td> 名前:<input type="text" name="name" id="name"> 内容:<textarea name="comment" cols="30" rows="3" id="comment"></textarea> <input type="radio" name="bbs" id="r1" value="post">投稿 <input type="radio" name="bbs" id="r2" value="update">更新 <input type="radio" name="bbs" id="r3" value="delete">削除 <input type="submit" id="send"> </td> </tr> </table>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/23 05:00 編集
2016/09/23 05:05
2016/09/23 05:43
2016/09/23 05:57
2016/09/23 05:58
2016/09/23 06:22 編集
2016/09/23 06:15
2016/09/23 07:23
2016/09/23 07:29
2016/09/23 07:38
2016/09/23 07:45
2016/09/23 07:49