Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
Javascript 一旦使用jQuery中的.html函数输出了html,jQuery能否再次将其作为目标?_Javascript_Jquery_Html_Function - Fatal编程技术网

Javascript 一旦使用jQuery中的.html函数输出了html,jQuery能否再次将其作为目标?

Javascript 一旦使用jQuery中的.html函数输出了html,jQuery能否再次将其作为目标?,javascript,jquery,html,function,Javascript,Jquery,Html,Function,我遇到了一个问题,即从一些JSON数据生成一个选项列表,然后使用.html函数输出到DOM /* Function to get eventd based on subject areas */ function checker() { var eventstext = ''; // Create eventstext $('#customise-1 input[type=checkbox]:checked'

我遇到了一个问题,即从一些JSON数据生成一个选项列表,然后使用.html函数输出到DOM

          /* Function to get eventd based on subject areas */
          function checker() {
            var eventstext = ''; // Create eventstext
            $('#customise-1 input[type=checkbox]:checked').each( function(){
              var subject = $(this).val(); // Define subject
              var events = times[subject]; // Define events as subsect of JSON
              /* Loop through JSON data and add input details of each subject area */
              for (var i in events) {
                eventstext += '<div class="checkbox"><label><input class="times-check times-checker" type="checkbox" value="'+events[i].value+'">'+events[i].name+' : '+events[i].startTime+' to '+events[i].endTime+'</label></div>';//output checkboxes
              }
            });
            $('#sessiondisplay').html(eventstext);//output the data in this div
          }
          /* Happens on UG date selection */
          $('#ug-dateselector').change(function() {
            checker();
          });
          /* ALso happens when you select an option from the course list */
          $('#customise-1 input[type=checkbox]').click( function() {
            checker();
          });
我将类的times check添加到.html函数中,但是验证函数不起作用,它使用#times none,最后是else语句

我很感激能提供的任何帮助


谢谢大家!

您在哪里触发“if($(“#times none”)。is(':checked'){”代码?您可以通过同时从单个元素中删除所有类来大大缩短此代码-
$(“#ug-dates-times-1”)。removeClass('has-warning has error has success');
。此外,您的语法不正确-
$(
这是什么意思“验证函数不起作用”?代码没有这样编写的原因是团队的其他成员能够维护代码,这肯定不会改变验证函数?除非我在HTML页面中添加复选框,否则if-else语句和else-if语句都不起作用
<div id="sessiondisplay">
                        </div>
                        <div class='checkbox times-none'>
                          <label>
                            <input type='checkbox' id='times-none' class="times-checker" value=''>
                            I don't want to attend any events
                          </label>
                        </div>
  if ($('#times-none').is(':checked')) {
                    console.log('do not want to attend checked');
                    $($('#customiseDayTimesStatus')).removeClass('glyphicon-warning-sign');
                    $($('#customiseDayTimesStatus')).removeClass('glyphicon-remove');
                    $($('#customiseDayTimesStatus')).addClass('glyphicon-ok');
                    $($('#ug-dates-times-1')).removeClass('has-warning');
                    $($('#ug-dates-times-1')).removeClass('has-error');
                    $($('#ug-dates-times-1')).addClass('has-success');
                    $($('#ug-datesErrorMsg')).text('Done');
                    submittable = 0;
                  } else if ($('.times-check').is(':checked')) {
                    console.log('checked');
                    $($('#customiseDayTimesStatus')).removeClass('glyphicon-warning-sign');
                    $($('#customiseDayTimesStatus')).removeClass('glyphicon-remove');
                    $($('#customiseDayTimesStatus')).addClass('glyphicon-ok');
                    $($('#ug-dates-times-1')).removeClass('has-warning');
                    $($('#ug-dates-times-1')).removeClass('has-error');
                    $($('#ug-dates-times-1')).addClass('has-success');
                    $($('#ug-datesErrorMsg')).text('Done');
                  } else {
                    console.log('none checked');
                    $($('#customiseDayTimesStatus')).removeClass('glyphicon-warning-sign');
                    $($('#customiseDayTimesStatus')).removeClass('glyphicon-ok');
                    $($('#customiseDayTimesStatus')).addClass('glyphicon-remove');
                    $($('#ug-dates-times-1')).removeClass('has-warning');
                    $($('#ug-dates-times-1')).removeClass('has-success');
                    $($('#ug-dates-times-1')).addClass('has-error');
                  };
                });