Javascript jqueryclick函数只调用一次
正如标题所说,我有一些代码只触发单击事件一次。你们能看一下吗 更新: 我已经编辑了代码来显示整个功能。我正在为jQuery制作一个插件。无论如何,关键是代码确实有效,但是a.click的click函数只触发一次,只删除一个过滤器Javascript jqueryclick函数只调用一次,javascript,jquery,Javascript,Jquery,正如标题所说,我有一些代码只触发单击事件一次。你们能看一下吗 更新: 我已经编辑了代码来显示整个功能。我正在为jQuery制作一个插件。无论如何,关键是代码确实有效,但是a.click的click函数只触发一次,只删除一个过滤器 addFilterProcess: function () { var $this = this; var select_filters = this.select_filters; var selecte
addFilterProcess: function ()
{
var $this = this;
var select_filters = this.select_filters;
var selected_filter = select_filters.val();
if (selected_filter != 0)
{
if (this.active_filters.length == 0)
{
this.active_filters.push(selected_filter);
this.used_filters.append(this.template_show_filter(this.options.available_filters[selected_filter], selected_filter));
var filter = this.used_filters.find('#filter-'+selected_filter);
var a = filter.find('a');
a.click(function () {
$this.removeFilter(a.attr('filter'));
});
this.btn_apply_filters.show();
this.btn_cancel_filters.show();
this.btn_apply_filters.on('click', function () {
$this.applyFilters();
});
this.btn_cancel_filters.on('click', function () {
$this.cancelFilters();
});
/*
Reset the select, to show the first option
*/
select_filters.val(0);
}
else
{
if (this.active_filters.indexOf(selected_filter) === -1)
{
this.active_filters.push(selected_filter);
this.used_filters.append(this.template_show_filter(this.options.available_filters[selected_filter], selected_filter));
/*
Reset the select, to show the first option
*/
select_filters.val(0);
}
}
}
},
试一试
$this在中似乎未定义。请单击处理程序。什么是。removeFilter?这是指什么?我们应该如何才能帮助你,而不需要帮助?在您发布的代码中,没有任何内容可以说明为什么事件处理程序只能调用一次。只触发一次,只删除一个筛选器。这到底是什么意思?您是否希望一次单击即可删除多个筛选器?如果是,您希望删除哪些过滤器?a.attr'filter'返回什么?$this.removeFilter是如何工作的?或者,如果您再次单击该元素,事件处理程序是否不会再次调用?问题是什么还不清楚,你只提供了不完整的信息。同样,请提供一份报告。您提供的信息越多,我们就越容易帮助您或您自己解决问题。您所说的只触发一次单击事件是什么意思?我没有看到任何触发单击事件的东西,我看到的只是绑定单击处理程序的代码。默认情况下,jQuery没有removeFilter方法。还有,为什么你认为这能解决OP问题呢?伙计,这是我代码的一部分,这不是重点。这行不通。正如我所说,我的代码确实有效,但click函数只会被激活once@M.Mar还显示removeFilter方法实现,可能调用此方法会影响元素的处理程序,甚至元素本身,例如,发生删除。这不是removeFilter方法,因为它不会在第二次触发。因此它甚至不调用removeFilter方法
$(this).removeFilter(a.attr('filter'));