2014-12-27 83 views
-1
<a href="page.html" > <button type="button" id="proceed-button">Proceed </button></a> 

<input type="checkbox" name="checkbox3" value="yes"> 
By checking the box, I certify that have read the above disclaimers and agree to the rules. </input> 

我有一个复选框和一个按钮,将带我到下一页。但是,在按下按钮之前,必须勾选复选框。如果没有,则必须在复选框下方显示一个标签,标明“首先接受规则”。帮帮我?此外,如果我点击继续而不选中复选框,则可以突出显示复选框为红色。可以使用javascript/jquery。单击继续之前的复选框验证按钮

+0

哪里是你的JavaScript函数来做到这一点。你在问这个问题之前是否研究过这个问题? – Mouser 2014-12-27 20:00:05

+0

我要求的JavaScript来做到这一点。 – 2014-12-27 20:00:49

+0

可以使用jQuery吗? – 2014-12-27 20:01:13

回答

3

试试这个它的工作原理

<form action="page.html"> 
 
<input type="checkbox" name="checkbox3" value="yes" required> 
 
By checking the box, I certify that have read the above disclaimers and agree to the rules. </input> 
 
<input type="submit" name ="submit"/> 
 
</form>

+0

虽然我更喜欢用这种方式,他希望JS代码! – 2014-12-27 20:09:56

+0

完美的作品。非常感谢。 – 2014-12-27 20:13:10

-1

为了让你开始:

<input id="checkboxAgree" type="checkbox" name="checkbox3" value="yes"> 
function checkAgree() 
{ 
    if (document.getElementbyId("checkboxAgree").getAttribute("checked"))//checkbox is checked 
    { 
     location.href = "page.html"; //load the next page. 
    } 
    else 
    { 
     Alert("You need to check the box before you can continue"); 
    } 

} 

document.getElementById("proceed-button").addEventListener("click", checkAgree ,false); 

addEventListener一个onclick事件添加到button。点击后,将执行功能checkAgree。当复选框具有属性checked时,将检查该复选框,并且if将呈现为真。 location.href将加载page.html

请删除围绕您的按钮的a