Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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
Php 发布表单不使用jquery字段_Php_Jquery_Html_Dom_Post - Fatal编程技术网

Php 发布表单不使用jquery字段

Php 发布表单不使用jquery字段,php,jquery,html,dom,post,Php,Jquery,Html,Dom,Post,我不能让表单使用动态字段将变量发布到另一个脚本 编辑:该脚本创建了一行新的输入字段,但没有一个字段能够将变量发布到php脚本中 jquery: <script type="text/javascript"> $(function(){ var newRowNum = 2; $('#addnew').click(function(){ // increment the counter

我不能让表单使用动态字段将变量发布到另一个脚本

编辑:该脚本创建了一行新的输入字段,但没有一个字段能够将变量发布到php脚本中

jquery:

<script type="text/javascript">
    $(function(){

            var newRowNum = 2;


            $('#addnew').click(function(){
                    // increment the counter
                    newRowNum += 1;

                    var addRow = $(this).parent().parent();


                    var newRow = addRow.clone();


                    $('input', addRow).val($(this).val());
                    $('name', addRow).val('os' + newRowNum);


                    $('td:last-child', newRow).html('<a href="" class="remove">Remove<\/a>');


                    $('input', newRow).each(function(i){
                            var newID = 'os' + newRowNum + i;
                            $(this).attr('id',newID).attr('name',newID);
                    });



                    addRow.before(newRow);


                    $('a.remove', newRow).click(function(){
                            $(this).parent().parent().remove();
                            return false;                           
                    });


                    return false;
            });
    });

$(函数(){
var-newRowNum=2;
$('#addnew')。单击(函数(){
//递增计数器
newRowNum+=1;
var addRow=$(this.parent().parent();
var newRow=addRow.clone();
$('input',addRow).val($(this.val());
$('name',addRow).val('os'+newRowNum);
$('td:last child',newRow).html('

我看不到您正在初始化变量
I
。我们看不到所有的源代码,但我想这可能就是问题所在。

输入元素应该在元素内部…

为什么不把计数器丢了,这样做:

<input name="os[]" type="text" class="os" value="" size="24" maxlength="60" /> 

动态添加行后,必须绑定('click')或只使用live()方法。


函数postMyForm()
{
$.ajax({
url:“要发布到的文件的url”,
数据:$('#myForm')。序列化(),
键入:“post”,
成功:功能(数据){
//当请求完成时做一些事情
}
});
}
函数AddNewRule(){
//获取最后一个ID
//将其转换为整数进行计数
var LastID=parseInt($('#myTable tr:last td input').attr('id').replace(/os/gi'));
//添加1以获取下一个ID
LastID+=1;//或LastID=LastID+1;您想使用什么
//创建新规则并设置下一个ID
var newRule=$('');
//在表的末尾追加/插入
$('#myTable').append(newRule);
}

仅初始创建的字段(os21、os22和os23)是到达服务器还是什么都没有?我不明白,你到底想要什么。你想通过ajax或??????@polarblau发布到php脚本吗?是的,只有那些字段到达,而不是动态字段。@Tricker我试图通过post添加要发布到php脚本的字段。如上所述,只有字段(os21、os22和os23)工作。对我来说很好客户端的工作:-也许你的服务器端脚本有问题?脚本运行良好,通过添加字段等,你能得到动态字段来发送变量吗?我如何在上面的脚本中实现这一点?我想放弃计数器。
<input name="os[]" type="text" class="os" value="" size="24" maxlength="60" /> 
<script language="text/javascript">
    function postMyForm()
    {
        $.ajax({
            url: "url from your file to post to",
            data: $('#myForm').serialize(),
            type: 'post',
            success: function(data) {
                // do stuff when request is done
            }
        });
    }

    function AddNewRule() {
        // get last ID
        // convert to a int to count with it
        var LastID = parseInt( $('#myTable tr:last td input').attr('id').replace(/os/gi, '') );
        // add 1 to get next ID
        LastID += 1; // OR LastID = LastID + 1;  what you wanna use

        // create new rule and set the next ID
        var newRule = $('<tr><td><input name="os'+ LastID +'" type="text" id="os'+ LastID +'" value="" size="10" maxlength="60" /></td></tr>');

        // append / insert at the end of your table
        $('#myTable').append(newRule);
    }
</script>

<form id="myForm">
<table id="myTable">
    <tr>
        <td>
            <input name="os21" type="text" id="os21" value="" size="24" maxlength="60" />
        </td>
    </tr>
    <tr>
        <td>
            <input name="os22" type="text" id="os22" value="" size="24" maxlength="60" />
        </td>
    </tr>
    <tr>
        <td>
            <input name="os23" type="text" id="os23" value="" size="10" maxlength="60" />
        </td>
    </tr>
</table>
    <a id="addnew" onclick="AddNewRule();"  href="javascript:void(0);">Add +</a>
<table>
    <tr>
        <td colspan="3" align="left" style="text-align: right; padding-top: 10px;">
            <input type="submit" onclick="postMyForm();" value="Update">
        </td>
    </tr>
</table>
</form>