gpt4 book ai didi

javascript - 如果没有选择单选按钮,则显示alert()

转载 作者:行者123 更新时间:2023-11-28 16:07:53 24 4
gpt4 key购买 nike

单击“删除”按钮后,如果未选择任何单选按钮,如何显示警报。我的 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");
}
}

最佳答案

也许检查“已检查”状态不起作用?

//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/

关于javascript - 如果没有选择单选按钮,则显示alert(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14132651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com