Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.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 动态添加的表单字段不';t发送到服务器_Javascript_Php_Jquery_Forms - Fatal编程技术网

Javascript 动态添加的表单字段不';t发送到服务器

Javascript 动态添加的表单字段不';t发送到服务器,javascript,php,jquery,forms,Javascript,Php,Jquery,Forms,我在单击按钮时动态添加一个字段,代码如下: jQuery("#yasr-add-field-edit-multiset").on('click', function() { var newTextBoxDiv = jQuery(document.createElement('tr')) newTextBoxDiv.html(' \ <td colspan="2">Element #' + counter + ' <input type=

我在单击按钮时动态添加一个字段,代码如下:

jQuery("#yasr-add-field-edit-multiset").on('click', function() {
var newTextBoxDiv = jQuery(document.createElement('tr'))

newTextBoxDiv.html(' \
                    <td colspan="2">Element #' + counter + ' <input type="text" name="edit-multi-set-element-' + counter + ' " value="" > \
                    <input type="hidden" name="stored_field_id_for_row_' + counter + ' " value=" ' + counter + ' "></td> \
                  ');

newTextBoxDiv.appendTo("#yasr-table-form-edit-multi-set");
jQuery(#yasr add field edit multiset”)。在('click',function()上{
var newTextBoxDiv=jQuery(document.createElement('tr'))
newTextBoxDiv.html('\
元素#'+计数器+'\
\
');
newTextBoxDiv.appendTo(#yasr表格编辑多集”);
这是显示的表单和表格

<form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
    <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />


        <table id="yasr-table-form-edit-multi-set">
            <tr>

                <td id="yasr-table-form-edit-multi-set-header"> 
                     //Code
                </td>

                 <td id="yasr-table-form-edit-multi-set-remove"> 
                    //code
                 </td>

            </tr>
        </table>
</form>
我根据您的代码创建了一个

它添加了字段,但不幸的是,JSFIDLE阻止了
POST
ing
表单
s。因此,我只能使用
$.serialize
查看将从
表单
发送哪些字段

根据我的测试,它
$。serialize
收集了所有必要的数据,当
发布
表单时也会发生同样的情况

形式

控制台输出
$。序列化

yasr_edit_multi_set_form=1&
edit-multi-set-element-0=hello&
stored_field_id_for_row_0=0&
edit-multi-set-element-1=world&
stored_field_id_for_row_1=1 
我猜你的问题出在其他地方。确保检查(Chrome dev tools/Firebug)发布的实际数据,看看它们是否从浏览器发送


如果它们被发送,问题就出在后端。

OT:
jQuery(document.createElement('tr'))
应该是
jQuery(“”)
。你能用你的代码做一个jsfiddle吗?看起来它应该可以工作,但可能我遗漏了什么。浏览器是否插入了TBODY元素?如果是这样,插入的TR将随后出现并且无效。是的,Jim,我没有注意到:浏览器添加了TBODY元素,但新的TR被附加在tbodyInteresting中。它似乎是jQuery句柄在这种情况下,您将附加到具有tbody的表。