2012-11-15 87 views
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> 

但當我勾選與背景出現窗口背景上的複選框,但我需要彈出窗口時出現只有當我勾選框並按下按鈕

+0

雖然我明白你想要什麼。你在這裏沒有給我們太多。你能否至少向我們展示你現在擁有的HTML代碼? – Codeguy007

+0

請參閱上面的編碼:) –

+0

'missinginfo + =「您必須同意條款和條件」;'僅用於觸發發送(如果存在)。應該'missinginfo =「」'是'missinginfo + =「」'?無論如何,這是多餘的。我不知道你有兩個如果陳述,當你會做。你有更多的代碼?也''='應該''==' – Codeguy007

回答

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

非常感謝你幫助了我很多,只是我會試着去設計這個窗口,或者這是不可能的? –

+0

看看這裏:http://stackoverflow.com/questions/7853130/how-to-change-the-style-of-alert-box – user4035

+0

PLZ,如果一切是好的,回答問題的標記。 – user4035

相關問題