Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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_Javascript_Jquery - Fatal编程技术网

Php 保持动态添加的行+;动态添加行上的jquery和服务器端验证

Php 保持动态添加的行+;动态添加行上的jquery和服务器端验证,php,javascript,jquery,Php,Javascript,Jquery,由于需要向表中动态添加/删除行,我使用以下jquery向表中添加/删除行: 在这里,我解决了更改输入标记的name属性的问题。 但在添加动态行时,在同一个表中获取post数据结果(同时进行服务器端验证)时,我遇到了一个问题。 有没有办法将动态php脚本设置为输入标记的value属性? 另外,如何在刷新后保留动态添加的行 $(文档).ready(函数(){ //此行克隆“.row”类中的行并将其转换为纯html。 var clonedRow=$('.row').clone().html() //此

由于需要向表中动态添加/删除行,我使用以下jquery向表中添加/删除行: 在这里,我解决了更改输入标记的name属性的问题。 但在添加动态行时,在同一个表中获取post数据结果(同时进行服务器端验证)时,我遇到了一个问题。 有没有办法将动态php脚本设置为输入标记的value属性? 另外,如何在刷新后保留动态添加的行

$(文档).ready(函数(){ //此行克隆“.row”类中的行并将其转换为纯html。 var clonedRow=$('.row').clone().html()

//此行包装clonedRow并包装它的标记,因为克隆会忽略这些标记
var appendRow=''+clonedRow+'';
//$('#btnAddMore')。单击(函数(){
//此行是最后一行,在找到正确的行时追加appendRow。
//$('.employmentHistoryForm tr:last')。在(附录行)之后;
//});
$(“#btnAddMore”)。单击(函数(){
$(“.employmentHistoryForm tr:last”)
.clone()
.附录(“.employmentHistoryForm”)
.find(“:输入”)
.attr('name',函数(索引,名称){
返回名称。替换(/(\d+)$/,函数(fullMatch,n){
返回编号(n)+1;
});
})
});
//当你点击“删除”按钮时,里面的功能就会被触发。
$('.deleteThisRow').live('单击',函数()){
var rowLength=$('.row').length;
//这一行确保我们永远不会用完行。
如果(行长>1){
删除(本);
}否则{
$('.employmentHistoryForm tr:last')。在(附录行)之后;
删除(本);
}
});
函数deleteRow(currentNode){
$(currentNode).parent().parent().remove();
}
});

我好像终于解决了这个问题。这更像是一个PHP问题,当我对输入标记的name属性使用数组并将POST数据响应返回到同一页面时,数据被持久化。
//This line wraps the clonedRow and wraps it <tr> tags since cloning ignores those tags
var appendRow = '<tr class = "row">' + clonedRow + '</tr>';  

//$('#btnAddMore').click(function(){
//this line get's the last row and appends the appendRow when it finds the correct row.
  //    $('.employmentHistoryForm tr:last').after(appendRow);
    //});

$("#btnAddMore").click(function() {
    $(".employmentHistoryForm tr:last")
        .clone()
        .appendTo(".employmentHistoryForm")
        .find(':input')
        .attr('name', function(index, name) {
        return name.replace(/(\d+)$/, function(fullMatch, n) {
        return Number(n) + 1;
        });
    })
});

//when you click on the button called "delete", the function inside will be triggered.
$('.deleteThisRow').live('click',function(){
    var rowLength = $('.row').length;
    //this line makes sure that we don't ever run out of rows.
    if(rowLength > 1){
deleteRow(this);
}else{
$('.employmentHistoryForm tr:last').after(appendRow);
deleteRow(this);
}
});

function deleteRow(currentNode){
$(currentNode).parent().parent().remove();
}
});