这段代码有什么问题.如果用户选择或未选择复选框,为什么仍显示MsgBox? [英] What's wrong in this code. Why does it still display the MsgBox if the user selects or does not select the checkbox?
问题描述
无论我是否选中复选框,它仍然会提供一个MsgBox ...
在以下两种情况下,我下面的代码都将重定向到Google:如果用户选中了该复选框,则它将重定向到www.google.com,但是如果用户忘记了选中复选框,则会显示带有确定按钮.当我单击确定"时,它应该重定向到www.google.com
My code below will redirect to Google in both conditions: If the user selects the checkbox, then it will redirect to www.google.com, but if a user forgets to check the checkbox then it shows the message box with an OK button. When I click on OK it should redirect to www.google.com
我想要
当用户忘记选中任何复选框以显示带有 OK 按钮的MsgBox并停留在同一页面上时.否则,如果用户选中任何复选框,则重定向到www.google.com.
When a user forgets to check any of the checkboxes to show a MsgBox with an OK button and stay on the same page. Otherwise if user selects any of the checkboxes then redirect to www.google.com.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<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 ="return 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 haven\'t selected an item yet!')
return false
}
</script>
</body>
</html>
推荐答案
该位?
for (i=0; i {
应该是这样的:
for (i=0; i <= loopnumber; i++)
{
}
这篇关于这段代码有什么问题.如果用户选择或未选择复选框,为什么仍显示MsgBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!