我有两个函数sidefilter
,另一个是topfilter
。
sidefilter();
function sidefilter(){
$('.sidefilter').unbind("click");
$('.sidefilter').on("click",function(e){
var fid=$(this).attr('data-id');
var filtertype=$(this).attr('data-type');
var type = $('.view-list').hasClass("active")?"list":"grid";
$.post(urljs+"user/FilterController/index",{'fid':fid, 'filtertype':filtertype, 'type':type},function(data){
$("#sidefilter").html(data.view);
sidefilter();
topfilter();
},"json");
e.preventDefault();
});
}
topfilter();
function topfilter(){
$("[name=topfilter]").unbind('change');
$("[name=topfilter]").on("change",function(e){
**I want to use trigger event here and use of that i want call sidefilter function. This topfilter is drop down input**
},"json");
});
}
<select class="select" data-type="topfilter" name="topfilter" id="all-categories">
<option value="">All</option>
<option value="1">Beginer</option>
<option value="2">Intermediate</option>
<option value="3">Professional</option>
</select>
答案 0 :(得分:2)
以下是如何使用trigger()
函数的示例:See this fiddle
<强> JS 强>
$('.sidefilter').click(function(){
alert('triggered!');
});
$("[name=topfilter]").on("change",function(e){
$('.sidefilter').trigger('click');
});
希望它有所帮助!