首页 > 解决方案 > 事件监听器:何时将 CSS 应用于动态内容

问题描述

需要将 CSS 应用于 event.listener 生成的内容。

在我的导航/过滤器菜单中,我单击一个项目,事件侦听器会生成一个新的动态填充的导航菜单/过滤器。它根据需要起作用,但我需要将 css 添加到单击的项目中以触发侦听器的输出。

例如,当我在这里构建 html 输出时,是否应该添加它。

dataset += "<p>"
           + "<input type="checkbox" 
id="sub_category:"+underscored_v+ "/>"+"<label 
for="sub_category:"+underscored_v+">"+v+"</label>"+"</p>";

还是我应该在这段代码中这样做(你会在底部看到我的尝试):

function update_secondary_filters(opts) {

  $.ajax({
    type: "POST",
    url: "/php-queries/product-filter-secondary-query.php",

    dataType: 'json',
    cache: false,
    data: {
      filterOpts: opts
    },
    success: function(records) {
      //console.log(records);
      //alert('SUCCESS!');
      // alert(records);
      $('#filtering_div').html(makeSecondaryFilter(records));
    }
  });
  // make the filter heading button show as active 
  var clicker = function() {
    $('sub_category:premium').each(function() {
      this.checked = true;
    });

  }
  clicker();
}

标签: javascriptcss

解决方案


推荐阅读