0

「削除」ボタンをクリックした後、ラジオボタンが選択されていない場合にアラートを表示する方法。私のhtmlフォーム

<form name="Action" method="post" action="RequestAction">
                    <table width="800px" cellpadding="5" style="color:black; border-top:1px solid #ccc;" border="0">
                    </table>
                    <div id="container">
                    <div id="demo_jui">
                    <table id="requestList" class="display" cellpadding="0" cellspacing="0" border="0" style="font-size:12px;" >
                    <thead id="headed">
                        <tr>
                            <th  align="center" title="Employee">Employee</th>
                            <th  align="center" title="Number of Days">Number of Days</th>
                            <th  align="center" title="Start Date">Start Date</th>
                            <th  align="center" title="End Date">End Date</th>
                            <th  align="center" title="Leave Type">Leave Type</th>
                            <th  align="center" title="Remark">Remark</th>
                            <th  align="center">Approve</th>
                            <th  align="center">Reject</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                    </table>
                    </div>
                    </div>
                        <table>                 
                        <tr>
                            <td style="padding-left:0px;" colspan="3">
                                <a href="#"><img src="images/Submit.png" style="border:none;" onClick="javascript:Go()"
                                onmouseover="this.src='images/Submit_Hover.png'" onmouseout="this.src='images/Submit.png'"/></a>
                                &nbsp;&nbsp;&nbsp;
                                <a href="#"><img src="images/Reset.png" style="border:none;" onClick="javascript:clearForm()"
                                onmouseover="this.src='images/Reset_Hover.png'" onmouseout="this.src='images/Reset.png'"/></a>
                            </td>
                        </tr>
                    </table>
                </form>

ラジオボタンの値がテーブルに取得されます。テストしたときに、ラジオボタンを選択せず​​に送信ボタンをクリックすると、エラーが発生します

関数Go()で、ラジオボタンを検証する方法は正しいですか?ありがとうございました

function Go() {
                if( $('form[name=Action] input[name=statusList]:checked').length == 0)
                {
                    $('form[name=Action]').submit();
                }
                else
                {
                    alert("Please select at least one to delete");
                }
            }
4

2 に答える 2

3

「チェック済み」ステータスのチェックが機能しない可能性がありますか?

//read value of radio button
alert($("input[name='radio-button-group']:checked").val());

//get bool, if radio button is checked
alert(typeof $("input[name='radio-button-group']:checked").val() != 'undefined');

ソース(ドイツ語):http://mabraham.de/jquery-radio-buttons-auslesen-und-manipulieren/

于 2013-01-03T03:47:44.960 に答える
1

以下のスニペットを使用してください

var IsChecked = $('take id or classname of radiogroup').is(':checked');

if(!IsChecked)
{
alert("select some thing");
}
于 2013-01-03T06:39:50.063 に答える