提问人:COBNETCKNN 提问时间:7/18/2022 更新时间:7/18/2022 访问量:112
将 checked 属性添加到选定的输入 ajax
Adding checked attribute to selected input ajax
问:
在 WordPress 上制作了一个带有自定义分类法的 ajax 过滤器,一切正常,但问题是当单击和显示新结果时,复选框没有得到选中属性。我不知道我在这里错过了什么?
[HTML全文]
<div class="categories">
<?php
$cat_args = get_terms(array(
'taxonomy' => 'position',
'orderby' => 'name',
));
$categories = $cat_args;
foreach($categories as $cat) : ?>
<label class="hotel-service block mb-2 font-montserrat text-altumTitle text-lg font-medium">
<input type="checkbox" value="yes" class="checkbox" data-category="<?php echo $cat->term_id ?>" href="<?php echo get_category_link($cat->term_id); ?>"> <?php echo $cat->name; ?></label>
<?php endforeach; ?>
</div>
Ajax 调用
(function($) {
$(document).ready(function(){
$(document).on('click', '.hotel-service > input', function(e){
e.preventDefault();
var category = $(this).data('category');
$.ajax({
url: wpAjax.ajaxUrl,
// filter here is handler for add_action callback function in ajax-filter.php
data: { action: 'hotelService', category: category},
type: 'post',
success: function(result) {
$('#response').html(result);
},
error: function(result) {
console.warn(result);
}
});
});
});
})(jQuery);
答: 暂无答案
评论
checkbox doesn't get checked attribute when click and new results are shown
$(window).on('ajaxcomplete'
success