3

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

我已经做到了,但我需要这个

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

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

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

4

1 回答 1

2

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

<!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>
于 2012-11-15T13:48:15.783 回答