HTML
<li class="leaf">
// The span is my custom checkbox that wraps around the default checkbox.
<span class="checkbox facetapi-checkbox checked">
// The span above replaces the default checkbox below, which you'll notice has a display:none; I don't want both checkboxes showing.
<input type="checkbox" class="facetapi-checkbox" checked="true" style="display: none; ">
</span>
// This is the anchor tag that I need to click when my custom checkbox is checked.
// It's outside of my custom checkbox span, but shares the same parent.
<a href="/part-finder/field_rep_catalog/heater-1527" rel="nofollow" class="facetapi-active facetapi-checkbox-processed" style="display: none; ">(-)
<span class="element-invisible">Remove Support filter</span>
</a>
</li>
这是用于用我的自定义复选框替换默认复选框的 jQuery:
//Checkbox Image Replacement
$('.faceted_search_column input[type=checkbox]').each(function() {
var span = $('<span class="' + $(this).attr('type') + ' ' + $(this).attr('class') + '"></span>').click(doCheck).mousedown(doDown).mouseup(doUp);
if ($(this).is(':checked')) {
span.addClass('checked');
}
$(this).wrap(span).hide();
});
// You'll notice that when this function is run, I've attempted to use .closest() to find the nearest anchor and then do a .triggerHandler('click') to click that anchor it finds. This obviously didn't work. Should I use .parent() to move back in the DOM?
function doCheck() {
if ($(this).hasClass('checked')) {
// This was my attempt to click the anchor when doCheck function is run.
$(this).closest('a.facetapi-checkbox-processed').triggerHandler('click');
$(this).removeClass('checked');
$(this).children().prop("checked", false);
} else {
$(this).parents('a.facetapi-checkbox-processed').triggerHandler('click');
$(this).addClass('checked');
$(this).children().prop("checked", true);
}
}
function doDown() {
$(this).addClass('clicked');
}
function doUp() {
$(this).removeClass('clicked');
}
当用户切换复选框时,你们推荐什么作为触发锚点点击的最有效方法?这是一个多面搜索锚,所以我需要选中或取消选中才能触发相同的锚标记。
提前感谢那些花时间帮助我的人。