Javascript 增加克隆行中输入字段的值

Javascript 增加克隆行中输入字段的值,javascript,jsp,servlets,Javascript,Jsp,Servlets,1) 这里我正在做一行的克隆…但这段代码只在eclipse中工作[即,克隆正在工作],而且在任何浏览器中都不工作 2) 获取克隆行中同名文本框的值并使用jsp和servlet插入数据库的解决方案是什么? 如何获得同名的值 3) 我有servlet代码,只从jsp获取单个值 String address_seq_num =request.getParameter("address_seq_num"); how can i get the value of address seq numb

1) 这里我正在做一行的克隆…但这段代码只在eclipse中工作[即,克隆正在工作],而且在任何浏览器中都不工作

2) 获取克隆行中同名文本框的值并使用jsp和servlet插入数据库的解决方案是什么? 如何获得同名的值

3) 我有servlet代码,只从jsp获取单个值

    String address_seq_num =request.getParameter("address_seq_num");

how can i get the value of address seq number in the cloned row fromjsp to servlet to insert into the next row of a table in the database.
4) 如果我在这段代码中提到“文档类型”,它在eclipse中也不起作用。。。。。 请引导我

JavaScript

function clonetable() {
 var x=document.getElementById("main_table"); //get the table 
var rowCount = x.rows.length; 
var row = document.getElementById("table_row_clone"); // find row to copy
var table = document.getElementById("table_body"); // find table to append to 
var clone = row.cloneNode(true); // copy children too 

var tb1 = clone.document.getElementById("asn");//here i'm incrementing the value     
tb1.value=rowCount+1;//of "address seq num " in the cloned row


    clone.id = "abc"; // change id or other attributes/contents 
    table.appendChild(clone); // add new row to end of table 
}

function deltable() {
    var x = document.getElementById("main_table"); //get the table 
    var rowCount = x.rows.length;
    if (rowCount > 1) {
        x.deleteRow(rowCount - 1);
    } //delete the last row 
}
HTML


地址详情
地址序号

根据您的HTML(顺便说一句,它很凌乱),您可以使用以下内容增加文本框的值:

var tb = document.getElementById("asn");
tb.value = parseInt(tb.value, 10) + 1;
诀窍是必须将文本框的值转换为数字,这就是parseInt在该示例中所做的


请注意,如果值不是有效数字,则上述代码段将在文本框中为您提供“NaN”-它根本不进行任何数据验证。

您在哪里递增?我在你的JS代码中没有看到,你的HTML标记很混乱,很多元素还没有关闭。我建议。您发布了一个更干净的html标记,元素标记有正确的结尾和结尾。感谢您的回复…实际上在这段代码中,我想在克隆后增加下一行的“Address seq number”…当前它的值是“1”…但我不知道如何做…我尝试了这段代码var tb=document.getElementById(“asn”);tb.value=parseInt(tb.value,10)+1;它会增加值,但它也会在连续添加时更改第一行值…感谢您的回复…我尝试了这段代码…它会增加值,但在连续添加时也会更改第一行值…是的,这意味着您有相同的id在各行中传播。您需要以某种方式唯一地标识该行。换句话说,document.getElementById(“asn”)每次只是抓取相同的文本框,因为它是页面上ID为“asn”的第一个元素。如果我写这段代码,它在eclipse中也无法工作……为什么?请转到此链接……我将图像粘贴到了这里。请引导我。
var tb = document.getElementById("asn");
tb.value = parseInt(tb.value, 10) + 1;