【问题标题】:Tick checkbox then submit and then pop up window勾选复选框然后提交然后弹出窗口
【发布时间】:2012-11-15 22:09:58
【问题描述】:

如果有人可以帮助我找到解决一个问题的方法,我将不胜感激,可能我需要非常简单的东西,但我不知道如何将它放在一起,所以我需要 - 包含勾选框的部分,然后按钮提交,但如果你不勾选复选框并按下按钮出现窗口,上面写着你必须做......,

我已经完成了,但我需要这个

但是,如果您勾选并按下按钮,应该会顺利出现仅包含文本信息的弹出窗口!我不知道如何得到它, 这是带有复选框和按钮的部分

    <form name="form" method="post" action="#" onSubmit="return checkme();">
    <input type="checkbox" name="agree" value="agree_terms" class="terms">
    &nbsp;I&acute;ve read terms and conditions and I&acute;m ready to shop
    <input type="submit" name="submit" value="" class="submit">
    </form>

这是javascript

    function checkme() {
        missinginfo = "";
        if (!document.form.agree.checked) {
            missinginfo += "You must agree to the Terms and Conditions";
        }
        if (missinginfo != "") {
            missinginfo ="" +
            "\n" +
            missinginfo + "" +
            "\n Please tick the box and try again.";
            alert(missinginfo);
            return false;
        }
        else {
            return true;
        }
    }

我尝试了不同的方式

    <body>
    <title>LIGHTBOX EXAMPLE</title>
    <style>
    .black_overlay{
    display: none;
    position: absolute;
    top: 0%;
    left: 0%;
    width: 100%;
    height: 100%;
    background-color: black;
    z-index:1001;
    -moz-opacity: 0.8;
    opacity:.80;
    filter: alpha(opacity=80);
    }
    .white_content {
    display: none;
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    padding: 16px;
    border: 16px solid orange;
    background-color: white;
    z-index:1002;
    overflow: auto;
    }
    </style>
    </head>
    <body>


    <p>This is the main content. To display a lightbox click <a href = "javascript:void(0)"
    onclick = "document.getElementById('light').style.display='block';        document.getElementById('fade').style.display='block'">here</a></p>

    <div id="light" class="white_content">This is the lightbox content. <a href =                 "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';                document.getElementById('fade').style.display='none'">Close</a></div>
    <div id="fade" class="black_overlay"></div>
    </body>
    </html>

但是当我勾选背景上的复选框时,会出现带有内容的窗口,但我需要只有在我勾选复选框并按下按钮后才会出现弹出窗口

【问题讨论】:

  • 虽然我明白你想要什么。你在这里没有给我们太多。您至少可以向我们展示您现在拥有的 HTML 代码吗?
  • missinginfo += "You must agree to the Terms and Conditions"; 仅用于触发发送(如果存在)。 missinginfo ="" 应该是 missinginfo +="" 吗?无论哪种方式,它都是多余的。我不知道你有两个 if 语句什么时候可以做。你有更多的代码吗? != 也应该是 `!=='

标签: javascript html checkbox popupwindow


【解决方案1】:

“如果你勾选并按下按钮应该会顺利出现只有文本信息的弹出窗口” - 你几乎做到了。只需将警报添加到第二个分支。试试这个代码:

<!DOCTYPE html>
<html>
  <!-- [[[ head -->

  <head>
    <title>element</title>
<script type="text/javascript">
  function checkme() {
        if (!document.form.agree.checked) {
            missinginfo = "You must agree to the Terms and Conditions\n Please tick the box and try again.";
            alert(missinginfo);
            return false;
        }
        else {
            alert("Text information");
            return true;
        }
    }
</script>
  </head>
  <!-- ]]] -->

  <body>
    <form name="form" method="post" action="#" onSubmit="return checkme();">
      <input type="checkbox" name="agree" id="agree" value="agree_terms" class="terms">
      <label for="agree">&nbsp;I&acute;ve read terms and conditions and I&acute;m ready to shop</label>
      <input type="submit" name="submit" value="Submit" class="submit">
    </form>
  </body>
</html>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多