$('bbs').on('click',function()から下の処理で何が足りないのかを教えてください
bbsがクリックされた時、ラジオボタンのID属性を判別してsubmitボタンの切り替えとチェックボックス非表示を行いたいんですが、$(this)でbbs自体に処理をさせる様にしてみたのに動きません
どういう事なんでしょうか
<script type="text/javascript" src="jquery-1.12.4.js"></script> <script type="text/javascript"> $(document).ready(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 ($('chkid[]:checked').length == 0) { window.alert("ERROR5"); return false; } } return true; }); $('bbs').on('click',function() {//bbsが押されたらsubmitボタンの切り替えとチェックボックス非表示の処理 var myid = $(this).prop('id'); var sendlist = { "r1":{"text":"投稿",checkflg:true}, "r2":{"text":"更新",checkflg:false}, "r3":{"text":"削除",checkflg:false}, }; if ($(this).prop('checked') == true) { $('#send').val(sendlist[myid].text); $('chkid[]').prop('disabled',sendlist[myid].checkflg); } }).click(); }); </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/21 06:23
2016/09/21 06:27
2016/09/21 07:00
2016/09/21 07:02
2016/09/21 07:54