注入表单元素后重新加载DOM? [英] Reload DOM after injecting form elements?

查看:128
本文介绍了注入表单元素后重新加载DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦用户执行某个操作,我试图将一些jQuery代码放入一个表单元素(输入复选框)中。后来用户可以提交这个表单。



我完全是jQuery的新手,但我已经设法组合了一些几乎可以工作的代码。这是我所得到的:

  $(#someDivID)load(myPage.asp?id = x ); 

myPage.asp生成一些表单元素,这一切都很好地显示在页面上。 >

但是,一旦提交(通过POST)表单,新的表单元素实际上并没有发布。这是表单提交功能:

  $(document).ready(function(){

var options = {};

//绑定表单的提交事件
$('#MyFormID')。submit(function(){
$(this).ajaxSubmit选项);
return false;
});
});

如果我完全错了,你必须原谅我,但我猜这是因为在初始加载DOM之后生成新的表单元素。我必须重新加载DOM(如果是这样吗?),或者我应该做的不一样?



最好的问候,
Adam

解决方案

这不是在表单中添加更多元素的问题。



您需要确保在表单元素本身或表单的子元素中添加输入元素(无论是复选框还是任何内容)(加载到您的案例中)。此外,您是否检查输入的名称属性?没有名字,输入将不会被发布。



BTW:ajaxSubmit有什么作用?


I'm trying to put together some jQuery code that will add form elements (input checkboxes) to a form, once the user performs a certain action. Later on the user can then submit this form.

I'm entirely new to jQuery, but I've managed to put together some code that almost works. Here's what I've got:

$("#someDivID").load("myPage.asp?id=x");

myPage.asp generates some form elements, and this all shows up nicely on the page.

However, once I submit (through POST) the form, the new form elements are not actually posted. Here's the form submit function:

$(document).ready(function() {

    var options = {};

    // bind to the form's submit event
    $('#MyFormID').submit(function() {
      $(this).ajaxSubmit(options);
      return false;
    });
});

You'll have to excuse me if I'm totally wrong on this, but I'm guessing it's because the new form elements are generated after the DOM is loaded initially. Do I have to reload the DOM (and if so how?), or should I be doing the whole thing differently?

Best regards, Adam

解决方案

It's not a question of adding more elements to the form.

You need to make sure that the input elements (be it checkboxes or whatever) are appended (loaded in your case) to either the form element itself or a child element of the form. Moreover did you check the input's name attribute? Without a name the input won't get posted.

BTW: What does ajaxSubmit do?

这篇关于注入表单元素后重新加载DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆