javascript - 事件监听器:何时将 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();
}
解决方案
推荐阅读
- oracle - 在某些情况下显示“选择列表”
- sql - 使用 SQL 连接两个表并插入年份列
- c# - async 和 await,期待 main 中的非阻塞
- oauth-2.0 - 使用 phpleague/oauth2-client 发出 POST REQUEST
- excel - Excel 文件不使用 .Close 方法关闭
- java - 使用 hibernate 和 @JsonIgnore 获取 oneToMany 和 manyToOne
- actions-on-google - 我的 Action 和 webhook 作为草稿运行良好,但在提交到生产环境后失败
- visual-studio - 无法在 Visual Studio 17 解决方案资源管理器中删除文件(无错误消息)
- android - 如何在 ARCore 场景表单中渲染父节点右侧的视图
- excel - 将活动单元格从选定范围复制到第一个空单元格