2013-04-16 49 views
-3

如何发出弹出警报,以便当用户单击按钮并且未选中复选框时,将使用jQuery显示警报?如果在按钮单击时未选中复选框,则显示警报

该复选框是:

<input type="checkbox" id="confirm" class="confirm"> 

按钮是:

<form action="resetprocess.php" method="POST"> 
    <button type="submit" id="reset" class="btn btn-danger">Reset <i class="icon-repeat"></i></button> 
</form> 

回答

4

您需要捕捉按钮的点击事件,然后选中该复选框是否被点击或不。如果没有,你可以发送提醒并返回false(一定要这样做,否则表单将被提交)。

$('#reset').click(function() { 
    if (!$('#confirm').is(':checked')) { 
     alert('not checked'); 
     return false; 
    } 
}); 

jsFiddle example

+0

你的回报是,失踪的事情,我感谢你伟大的先生。 – user2146226

1
$("#reset").on('click',function(){ 
    if(!$("#confirm").is(':checked')){ 
    // alert(""); 
    } 
}); 
1
$("#reset").click(function(){ 
    if ($("#checkbox:checked").length == 0) 
     alert("Checkbox not checked!"); 
}); 
相关问题