2014-12-27 76 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