gpt4 book ai didi

javascript - 每次单击按钮时都会显示消息框,此代码中的实际问题是什么。

转载 作者:行者123 更新时间:2023-11-28 12:48:24 25 4
gpt4 key购买 nike

如何修复代码中的错误..如果用户选择不选择复选框,此代码将始终显示消息框..

但我希望如果用户没有选择任何复选框或忘记选择复选框,那么消息框将出现以其他方式重定向到其他页面..

<form id="form1" runat="server">
<div>

<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CheckBox ID="CheckBox2" runat="server" />

</div>
<asp:Button ID="Button1" runat="server" OnClientClick ="ConfirmSelection(this.form)" Text="Button" />


</form>
<script type="text/javascript">
function ConfirmSelection(frm)
{
for (i=0; i<=1; i++) {
//chkSubjectOfInterest is the id of your checkbox control

if (frm.elements[i].name.indexOf('chkSubjectOfInterest') !=-1)
{
if (frm.elements[i].checked)
{
return true
}
}
}
alert('You havent selected an Item yet!')
return false
}
</script>

最佳答案

你就不能用这个吗?

if (document.getElementById('<%=CheckBox1.ClientID%>').checked)
{
// do something
}

或者

if (document.getElementById('<%=CheckBox2.ClientID%>').checked)
{
// do something
}

关于javascript - 每次单击按钮时都会显示消息框,此代码中的实际问题是什么。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4818768/

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