如何在jquery ajaxform插件中使用$(this)
我使用 ajaxform 在类似的字段集中有 3 个表单。我想要的是当更新表单时,它应该只更新其父字段集。现在发生的事情是因为我没有 $(this) 变量,我无法指定 ajaxform,我只想更新提交的表单:
$(".toggle-form-submit").parents("form").ajaxForm({
dataType: 'html',
success: function(html) {
var myForm = $(this);
console.log(myForm);
if(myForm.parents("fieldset").find(".replaceable").length) {
updateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
} else {
longPanelUpdateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
}
if( $(".test-categories-list").length) {
initSortableTestCases();
}
}
});
显然 myForm 是响应对象。我想要的是当前表单的 jquery 选择器,以便它可以找到它的父级。我无法在 ajaxform 实例化中设置变量,那么我应该在哪里设置 $(this)/myForm?
i have 3 forms in similar fieldsets using ajaxform. What i want is when a form is updated, it should only update its parent fieldset. what happens right now is because i don't have a $(this) variable i can't specify ajaxform that i only want to update the submitted form:
$(".toggle-form-submit").parents("form").ajaxForm({
dataType: 'html',
success: function(html) {
var myForm = $(this);
console.log(myForm);
if(myForm.parents("fieldset").find(".replaceable").length) {
updateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
} else {
longPanelUpdateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
}
if( $(".test-categories-list").length) {
initSortableTestCases();
}
}
});
Apparently myForm is the response object. what i want is the jquery selector for the current form so that it can find it's parents. I can't set a variable in the ajaxform instantiation so where should i set $(this)/myForm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您正在使用此 jQuery Ajax 表单插件,则 success 方法的第四个参数将是执行操作的 jQuery 包装表单:
http://jquery.malsup.com/form/#options-object
所以这应该有效:
Assuming you are using this jQuery Ajax form plugin, the 4th argument of the success method will be the jQuery wrapped form that was acted on:
http://jquery.malsup.com/form/#options-object
So this should work: