防止JS移至另一页

时间:2018-08-21 07:52:24

标签: javascript

我需要防止用户在单击“提交”按钮(代码)后移动到另一页

<div class="form"><div class="pull-left"><input type="checkbox" name="agree" value="check"> I have read and agree to the <a href="#" target="_blank" class="agree"><b>Copyright Declaration</b></a></div></div>

 <button type="submit" name="add" id="addtocart" class="btn" onclick="if(!this.form.agree.checked){alert('You must agree to the Copyright Declaration.');return false}" > 

1 个答案:

答案 0 :(得分:0)

在表单标签中创建一个名为

的属性
onsubmit="if(!this.form.agree.checked){alert('You must agree to the Copyright Declaration.');return false}"