我使用jquery插件,统一,所以在我的表单上我可以有漂亮的单选按钮,和文件输入等
然而,我遇到了一个问题,很多我的表单通过ajax拉进来,显然,对于插件的工作,它需要知道元素存在于dom。
是否有办法使用插件与ajax方法?
当前我正在尝试,
$(".uniform input").live().uniform();
显然不起作用,有什么建议吗?
——在LOAD CALLBACK中实现-----
$('#upload').click(function(e) {
$("#content #main").animate({"right": "-900px"}, 'slow', 'linear', function(){
$(this).load('upload.html #main div', '', function(){
$(".uploader input").uniform();
});
});
$("#main").animate({"right": "0px"}, 'slow', 'swing');
e.preventDefault();
});
回复评论:
.load
只不过是封装在另一个方法中的$.ajax
调用。它也有回调。
$(target).load("myurl.php",function(){
$("select").uniform();
});
编辑:我刚刚看到你的编辑。如果这不起作用,请确保你使用了正确的选择器来找到你想要应用插件的元素。
在添加到表单中的之后再次初始化uniform ,使用正常的
$('#forms').append(new_selects_from_ajax);
$("select").uniform();
你可以使用livequery插件,像这样:
$('.uniform input').livequery(function(){
$(this).uniform();
});
.live和.delegate之间的区别之一是链通性。请查看http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery对这方面的评论。在这种情况下,您可能会使用delegate。