我有这些功能:
TargetWorksheet.toggle_child_locations = function(id){ $("#location-children-"+id).slideToggle("slow"); } TargetWorksheet.get_child_locations = function(id,lvl){ //Ajax grab all children and targets,and display children $.get('child_locations',{ location_id: id,level: lvl},function(data){ $("#location-children-"+id).append(data); TargetWorksheet.toggle_child_locations(id); }); //Change onClick to just toggle since child data will now be loaded $("#location-toggle-"+id).click(function(){ TargetWorksheet.toggle_child_locations(id); }); }
这个电话:
$(function(){ TargetWorksheet.toggle_child_locations(2); $("#location-toggle-2").click(function(){ TargetWorksheet.get_child_locations(2,1); }); });
所以我附上一个点击事件到我的’link(#location-toggle-2),它切换子数据。首先点击,我想做一个ajax调用来检索子数据,但是我只想覆盖#location-toggle-2上的.click,以便它现在只是切换,而不是进行ajax调用。上面的代码不起作用,似乎没有覆盖.click,并且每次调用ajax。
有人知道如何覆盖项目的.click事件?我也试过
$(“#location-toggle-”id).click(TargetWorksheet.toggle_child_locations(id));
由于某种原因,它不断地反复转动。
思考?