使用JQuery和PHP的动态fom问题

时间:2011-07-20 12:52:36

标签: php jquery forms

我正在做一个发票系统,我正面临一个问题。

想象一下一个简单的发票,你有行(行,元组,等等)你放置你买的东西,数量,价格等。

所以,在我的剧本中,我有一个这样的表格:

<form action='I-process-the-form-but-not-see-data.php'>
   <input ... //some other imputs (client,date,etc)

   <table>
   //table hedaers
      <tr>
      <td><input type='text' name='invoiceData[0][name]' /></td>
      <td><input type='text' name='invoiceData[0][amount]' /></td>
      <td><input type='text' name='invoiceData[0][price]' /></td>
   </tr>
</form>

我提供了一个在发票上添加一行的按钮。我是用JQuery做的。

我首先得到第一个并克隆它。将invoiceData [0]替换为invoiceData [COUNTER](全局计数器),一切看起来都很棒。

问题是我的数据没有发送到php脚本。我得到的唯一数据是静态输入(首次加载)。不是我用jquery添加的那个。

我用萤火虫检查了它,它正在添加新的线条。

实际上,如果我将JQuery生成的代码粘贴到静态表单中,它就会很好地发送它。

可能会发生什么?

编辑(JQUERY MAGIC):

var clon = $("#selectorForTR").clone().html(); //there is a minimal workaround for this but doesn't matters
clon = $(html.replace(/invoiceData\[0\]/ig, "invoiceData["+contador+"]"));
$("#tableBody").append(clon);

2 个答案:

答案 0 :(得分:0)

您确定要将生成的html附加到正确的位置吗?即,在表格标签内?如果数据没有通过,那是我唯一能想到的东西! :

答案 1 :(得分:0)

确保您正在打开和关闭克隆的tr,我认为这就是它只能获得一行的原因。

<tr> ...html... </tr>

请参阅我的示例:http://jsfiddle.net/wADef/

将其更改为在jsFiddle中工作,但请查看并告诉我。