Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 遍历表字段,并通过电子邮件发送值_Javascript_Php_Loops_Html Table_Field - Fatal编程技术网

Javascript 遍历表字段,并通过电子邮件发送值

Javascript 遍历表字段,并通过电子邮件发送值,javascript,php,loops,html-table,field,Javascript,Php,Loops,Html Table,Field,我有这样的桌子: <tr class="product"> <td><input class ="parts" id="tf1" type="text" style="width:327px"/></td> <td><input class ="parts" id="tf2" type="text" style="width:51px";"/></td> <td><input class

我有这样的桌子:

<tr class="product">
 <td><input class ="parts" id="tf1" type="text" style="width:327px"/></td>
 <td><input class ="parts" id="tf2" type="text" style="width:51px";"/></td>
 <td><input class ="parts" id="tf3" type="text" style="width:144px";"/></td>
 <td><input class ="parts" id="tf4" type="text" style="width:64px";"/></td>
 <td><input class ="parts" id="tf5" type="text" style="width:81px";"/></td>
 <td><input class ="parts" id="tf6" type="text" style="width:12px";"/></td>
 <td><input class ="parts" id="tf7" type="text" style="width:21px";"/></td>
 <td><input class ="parts" id="tf8" type="text" style="width:22px";"/></td>
 <td><input class ="parts" id="tf9" type="text" style="width:22px";"/></td>
 <td><input class ="parts" id="tf10" type="text" style="width:60px";"/></td>
 <td><input class ="parts" id="tf11" type="text" style="width:35px";"/></td>
 <td><input class ="parts" id="tf12" type="text" style="width:41px";"/></td>
 <td><input class ="parts" id="tf13" type="text" style="width:50px";"/></td>
 <td><input class ="parts" id="tf14" type="text" style="width:44px";"/></td>
 <td><input type="button" class="addRow" value="Add"/></td>
 <td><input type="button" class="delRow" value="Delete"/></td>
</tr>

假设您的addRow和delRow按钮正在工作,因为您没有提到任何相关内容:

将输入名称改为数组。所以不是

<td><input class ="parts" id="tf1" type="text" style="width:327px"/></td>
<td><input class ="parts" id="tf2" type="text" style="width:51px"/></td>
<td><input class ="parts" id="tf3" type="text" style="width:144px"/></td>

你应该使用

<td><input class ="parts" id="tf1" name="tf[]" type="text" style="width:327px"/></td>
<td><input class ="parts" id="tf2" name="tf[]" type="text" style="width:51px"/></td>
<td><input class ="parts" id="tf3" name="tf[]" type="text" style="width:144px"/></td>

使用PHP处理时,所有值都将以数组形式以$_POST['tf']的形式显示,从索引0开始。有了它,你可以循环浏览、处理并通过电子邮件发送


无论如何,我想知道为什么您的文本字段有不同的宽度和style=“width:327px”;“是一个错误的标记。

您打算如何发送/处理这些信息?您想只使用js吗?还是想使用php?我想把变量放在不可见的文本字段中,然后通过POST方法将其发送到php,然后格式化并通过电子邮件发送…html()方法只接收第一个元素。它不迭代。您可以对每个元素使用。因此我应该使用id作为数组?是的,我的添加和删除按钮正在工作。我使用不同的宽度,因为我需要不同大小的字段。并且--;“--是错误的,删除…由于没有固定数量的输入,将其发布到数组中更容易进行后处理。
<td><input class ="parts" id="tf1" name="tf[]" type="text" style="width:327px"/></td>
<td><input class ="parts" id="tf2" name="tf[]" type="text" style="width:51px"/></td>
<td><input class ="parts" id="tf3" name="tf[]" type="text" style="width:144px"/></td>