大佬教程收集整理的这篇文章主要介绍了Jquery – 在追加后执行回调,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$('a.ui-icon-cart').click(function(){ $(this).closest('li').clone().appendTo('#cart ul'); });
.each()
接受一个回调函数,并将其应用于jQuery对象中的每个元素。
想象这样的:
$('a.ui-icon-cart').click(function(){ $(this).closest('li').clone().appendTo('#cart ul').each(function() { $(this).find('h5').remove(); $(this).find('img').css({'height':'40px','width':'40px'}); $(this).find('li').css({'height':'60px','width':'40px'}); }); });
你也可以只存储结果,并改为:
$('a.ui-icon-cart').click(function(){ var $new = $(this).closest('li').clone().appendTo('#cart ul') $new.find('h5').remove(); $new.find('img').css({'height':'40px','width':'40px'}); $new.find('li').css({'height':'60px','width':'40px'}); });
我还建议,而不是mofiying CSS像你只是添加一个类到您克隆的li喜欢这样:
$(this).closest('li').clone().addClass("new-item").appendTo('#cart ul');
然后设置一些样式:
.new-item img,.new-item li { height: 40px; width: 40px; } .new-item h5 { display: none }
以上是大佬教程为你收集整理的Jquery – 在追加后执行回调全部内容,希望文章能够帮你解决Jquery – 在追加后执行回调所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。