如何使AjaxForm与使用jquery load()加载的几种表单一起工作? [英] How to make AjaxForm work with several forms loaded using jquery load()?
问题描述
我有一个带有div的页面,该页面使用分页器动态填充;-)在页面初始化时,我使用jquery .load()方法在其中加载了前10个表单.
I have a page with a div that is dynamically filled using a paginator ;-) At page init I load the first 10 forms in it using jquery .load() method.
我想做的是使用AjaxForm插件动态地更新所有表单.我知道服务器端,我们称之为update.asp.可以.
What I'd like to do is to make all the forms dynamically updatable using AjaxForm plugin. I know about server side, let's call it update.asp. It works.
但是有几个问题:
-
如何首先使插件起作用,因为AjaxForm似乎不适用于动态加载的div内的公司?
How to make plugin work in the first place as the AjaxForm seems not to work to the firms inside a dynamically loaded div?
我如何标识和命名表单?现在,我使用ID并将myForm命名为所有它们(也许这就是为什么它不起作用的原因).因为如果我使用名称myForm1,myForm2等...,我必须编写10个使用的ajaxForm函数:
How do I ID and name the forms? Now I used ID and name myForm to all of them (maybe that is why it doesn't work). Because if I use name myForm1, myForm2 etc... I have to write 10 ajaxForm functions that I use:
$('#myForm').ajaxForm({
beforeSubmit: showLoader,
success: hideLoader
});
然后我需要使用myForm1到myForm10进行10次吗?必须有另一种方式...
I would then need to make this 10 times using myForm1 to myForm10? There must be another way...
- 如何使AjaxForm处理尚未加载的页面?我认为这与1)是相同的问题.因为即使页面1也会以某种方式动态加载,但ajaxForm不会绑定到表单.
对不起,我对jquery还是很陌生,我正在努力研究它,在我写这篇文章之前,我尝试了一段时间.如果您能帮助我,我将非常感激.
Sorry, I am quite new to jquery, I am trying hard to study it, I tried this quite some time before I wrote here. If you can help me, I'd be very gratefull.
您的
杰里
这是我的加载器...不能正常运行,因为从未显示过该加载器,它消失得如此之快,只有在将警报放到hideLoader中时才能看到它:-((((
Here is my loader now... It is not working OK, as the loader is never shown, it dissapears so fast I can see it only if I put alert in the hideLoader :-(((
function load(num){
showLoader2();
var link='/obdelaneslike.asp?ID=<%=request.QueryString("IDRecept") %>&offset='+ num
$('#content').load(link, function(){
hideLoader2();
$('.ajax-loader').hide();
$('.myForm').bind("submit", function(event) {
$(this).ajaxForm({
beforeSubmit: showLoader($(this).find('img.ajax-loader').attr('id')),
success: hideLoader($(this).find('img.ajax-loader').attr('id'))
});
return false;
});
});
}
推荐答案
我将尝试一次解决这些问题,以更好地匹配该问题:
I'll try and address these one at a time to better match the question:
1),您可以在.load()
(或您使用的任何jQuery ajax方法)或使用类似
1) You can re-bind when you .load()
(or whatever jQuery ajax method you're using) or use a plugin like livequery()
, for example here's re-binding (do this in your success
handler):
$("#myDynamicDiv .myForm").ajaxForm({ ...options... });
或使用 livequery()
:
$(".myForm").livequery(function() { $(this).ajaxForm({ ...options... }); });
2)在此处使用类而不是ID,例如:class="myForm"
,每当您要处理诸如class
这样的成批元素时,这是一条相当安全的路线.上面的示例使用的是类,而不是每个表单的ID(它们可以有ID,只是不使用而已).您的表单标签如下所示:
2) Use a class instead of IDs here, like this: class="myForm"
, whenever you want to handle batches of elements like this class
is a pretty safe route. The examples above work with class and not IDs per form (they can have IDs, they're just not used). Your form tags would look like this:
<form class="myForm">
3)答案1中的相同解决方案也说明了这一点:)
3) The same solutions in answer #1 account for this :)
这篇关于如何使AjaxForm与使用jquery load()加载的几种表单一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!