Jquery plugins jQuery插件:重新附加插件本身失败
我有这个html:Jquery plugins jQuery插件:重新附加插件本身失败,jquery-plugins,jquery,load,click,Jquery Plugins,Jquery,Load,Click,我有这个html: <div class="item"> <ul> <li><a href="form.php" class="delete">delete</a></li> </ul> </div> <div class="item"> <ul> <li><a href="form.php" clas
<div class="item">
<ul>
<li><a href="form.php" class="delete">delete</a></li>
</ul>
</div>
<div class="item">
<ul>
<li><a href="form.php" class="delete">delete</a></li>
</ul>
</div>
<div class="item">
<ul>
<li><a href="form.php" class="delete">delete</a></li>
</ul>
</div>
据我所知,问题来自这一行:
$($cm.selector,object_parent).delete_string({targetElement:o.targetElement});
如果我这么做就好了
$($cm.selector).delete_string({targetElement:o.targetElement});
但这会将删除插件附加到屏幕上所有其他现有的删除按钮上,不是吗?为多个元素构建插件时,最好返回$。每个:
(function($){
$.fn.delete_string=function(options){
var defaults={
targetElement:'.item-needle',
targetSlibing:false
},options=$.extend(defaults,options);
return($(this).each(function(){
// Build your plug-in here
}));
};
})(jQuery);
您似乎正在从DOM树中删除该项,这意味着单击3次后,将没有剩余的项了?实际情况中有三个以上的项。实际上,这个插件最多可以点击两次,第三次点击就失败了。我已经更新了OP。谢谢。啊,看起来你在元素上丢失了ajax处理程序。不确定为什么只在单击两次后才会发生这种情况,但您可能需要重新注册Ajax事件$.delete…谢谢。你能再写一点我如何重新注册Ajax事件$.delete。。。。?谢谢看看这里。
(function($){
$.fn.delete_string=function(options){
var defaults={
targetElement:'.item-needle',
targetSlibing:false
},options=$.extend(defaults,options);
return($(this).each(function(){
// Build your plug-in here
}));
};
})(jQuery);