-2

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

<table id="main_table" align="center" style="width:75%">
    <tbody id="table_body">
        <tr id="table_row_clone">
            <td>
                <table align="center" style="width:100%">
                    <tr>
                        <td align="center">
                            <div style="border:3px solid silver;border-radius:5px;background-color:grey">
                                <table width="100%">
                                    <tr>
                                        <th align="center">Address Details</th>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF">
                                <table align="center" style="width:99%">
                                    <tr style="background-color:#1E90FF">
                                        <td style="width:35%">
                                            <table width="100%">
                                                <tr id="slrow">
                                                    <td style="width:43%">Address Seq Num</td>
                                                    <td>
                                                        <input id="asn" style="width:60px" name="address_seq_num" type="text" value="1" readonly>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td width="49%" align="right">
                                            <input style="width:80%" type="text" value="Reg.office/Primary Office">
                                        </td>
                                        <td align="right">
                                            <input style="width:30px" type="button" value="+" onclick="clonetable()">
                                            <input style="width:30px" type="button" value="-" onclick="deltable()">
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </tbody>

4

1 回答 1

0

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

var tb = document.getElementById("asn");
tb.value = parseInt(tb.value, 10) + 1;

诀窍是您必须将文本框的值转换为一个数字,这就是 parseInt 在该示例中所做的。

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

于 2013-08-27T17:56:29.607 回答