我有一个缩略图,单击该缩略图会链接到另一个页面。我想确保用户先选中复选框,然后才能单击缩略图转到其他页面。
我的 Javascript 函数当前是:
function CheckForm(obj1) {
if (obj1.accept.checked == false){
alert ("You must check the box to confirm you have read and accept the Terms.");
return false;
}
return true;
}
我的 html 看起来像这样:
<input name="accept" type="checkbox" value="0">Confirmation Box</input>
<a href="http://somelink.com">
<img src="/Koala.jpg" height="94" width="94" />
</a>
所以我希望用户必须先选中该复选框,然后才能单击 koala.jpg 缩略图。因此,用户访问 somelink.com 的唯一方法是选中该复选框。
最佳答案
<a href="http://somelink.com" onclick="return CheckForm()">
function CheckForm(obj1) {
if (!($('#accept').is(":checked"))){
alert ("You must check the box to confirm you have read and accept the Terms.");
return false;
}
return true;
}
关于javascript - 在转到其他页面之前检查复选框是否已选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15466489/