Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery复选框警报_Jquery_Django_Checkbox - Fatal编程技术网

jquery复选框警报

jquery复选框警报,jquery,django,checkbox,Jquery,Django,Checkbox,我继承了以下复选框: <td><div class="text_note"><label for="terms" class="text button_action"> <input type="checkbox" name="terms" id="terms" onClick="checkCheckBox(this, 'inf_terms', true)"> &nbsp;I understand and agree to the Term

我继承了以下复选框:

<td><div class="text_note"><label for="terms" class="text button_action">
<input type="checkbox" name="terms" id="terms"
onClick="checkCheckBox(this, 'inf_terms', true)">
&nbsp;I understand and agree to the Terms &amp; Conditions.
</label>&nbsp;<span id="inf_terms">&nbsp;</span></div></td>

我理解并同意这些条款&;条件
我需要编写一个jquery函数(新手),这样,如果条件条款的复选框未选中,就会出现一条警告消息,告诉用户在进入下一页之前选中该复选框。
Thx以获取任何帮助

这显示了如何为复选框设置onClick事件。它将在每次单击复选框时激发。。。我已经做了同样的提交按钮的想法作为id=buttonID

$(function() {
   //checkbox
   $("#terms").click(function(){
       //if this...
       //alert("this")...
       if($("#terms").is(':checked'))
       {              
          alert("im checked");
       }
   });
   //button
   $("#buttonID").click(function(e){
       if(!$("#terms").is(':checked'))
       {
           alert("you did not check the agree to terms..."); 
           e.preventDefault();
       }
   });
 }

我看到您的输入标记中有onClick javascript事件处理程序,如果您使用jquery提供的click事件函数,则不需要它,除非您让它做一些您没有提到的事情。但是要设置它,除非选中复选框,否则它将不会进入下一页,您必须知道单击的按钮才能进入下一页,假设按钮id为“button1”

 $(function(){
  $('#button1').click(function(){  
  if($('#terms').is(':checked'));
  {
  }
  else{
     alert("Please check the checkbox saying you agree with terms");
     return false;
   } 
 });
});

//(很抱歉,第一次错过了一个括号)

@Ana-您可以删除代码注释,我编辑了您的代码,使其现在可见。不幸的是,如果属性为空,则此操作将失败。仍然会开火。这就是你使用的原因。不是代替。是吗?那么.attr(“checked”)呢?看起来这是在我留下评论后编辑的,所以上下文丢失了。我现在觉得上面的一切都很好。。。我在过去使用过.attr(“checked”),但看起来.is和.not更好。。。当然更容易阅读…我认为如果存在伪选择器,应该使用它,因此在本例中,不需要attr()
if($("#terms:not(:checked)")) {

alert("some message");

};