jQuery新添加的输入未提交 [英] jQuery new added inputs are not submitted

查看:89
本文介绍了jQuery新添加的输入未提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多PHP生成的输入字段.使用jQuery添加新字段后,如果它们为空,则不会提交.但是,即使它们为空,也将发送静态的.

I have a lot of PHP generated input fields. Once I add new fields with jQuery they are not submitted if they are empty. However the static ones are sent even if they are empty.

我该如何解决?

代码:

<form id="sendform" action="pdf.php" method="post">
<input type="text" name="to1" />
<input type="text" name="to2" />
<input type="text" name="to3" />
<input type="submit" value="send" />
</form>

现在jQuery部分是:

Now jQuery part is:

var clone = $('input[name="to2"]').clone();
$(clone).attr('name', 'to4');
$('#sendform').append(clone);

屏幕截图:

您可以看到其中有Note1,Note2,Note3,Note4.我已经动态添加了Note2.您可以从屏幕截图中看到它在dom中,但是没有发送(是的,有数据输入).

You can see that there's Note1, Note2, Note3, Note4. I have added Note2 dynamically. You can see from the screenshot that it is in the dom, however it is not sent(yes, there's data inputted).

解决方案 总之,问题出在表(<table><form>)内的 元素中.当 成为表(<form><table>)的父表时,一切正常.

SOLUTION In conclusion the problem was in element placed inside the table(<table><form>). When became parent of a table(<form><table>) - everything works fine.

推荐答案

如果有人再次遇到相同的问题-原因可能很简单:格式错误的DOM. 这可能会导致正确的视觉呈现,但在提交时将无法正确处理表单输入

In case someone face same problem again - the reason can be pretty simple: malformed DOM. This may lead to correct visual rendering but will not handle form inputs correctly on submit

如果您有f.e.:

[form]
    [div]

    [div]
  [div] <!-- redundant closing div -->
[/form]

新添加的表单字段可能不会发送. 在Firefox中检查页面源-红色提示标签可能对您有帮助

Newly appended form fields may not be sent. Check page source in Firefox - red hinted tags may help you

这篇关于jQuery新添加的输入未提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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