我有一个缩略图,点击后链接到另一个页面。我想确保用户选中了一个复选框,然后用户可以点击缩略图进入另一页。
我的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的唯一方法是选中复选框。
答案 0 :(得分:3)
<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;
}
答案 1 :(得分:0)
问题在标签中列出了jquery,所以我假设您可以访问该库:
jQuery('#name').is(':checked') == false