2013-01-03 68 views
0

我試過這個添加行到表,但這是行不通的,甚至沒有給出任何錯誤,哪裏出錯?我已經添加計數器變量,這樣它會增加ID,使價值獲取存儲在數據庫中正確添加表格行使用jquery

<html> 
    <head> 

    <%--<script type="text/javascript" src="jquery-1.3.2.min.js"></script>--%> 

    <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    </head> 
    <body> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
    var counter = 2; 
    $("#addButton").click(function() { 
    if (counter > 10) { 
    alert("Only 10 rows allowed"); 
    return false; 
    } 
    $('#preq > tbody:last').append('<tr id="row'+counter+' "><td><input title="Enter Kind Of work '+counter+'" readonly="readonly" onclick="if(this.value!=''){this.value='';opendrop();}else{opendrop();}" id="other_work'+counter+'" name="other_work'+counter+'" type="text" size="30" <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_work'+counter+'']).'"'; } ?> ></td> <td><input name="client_name'+counter+'" size="40" type="text" id="client_name'+counter+'"/></td><td><input name="firm_name'+counter+'" size="40" type="text" id="firm_name'+counter+'" /> </td> </tr>'); 
     counter++; 
    }); 

    </script> 
    <table id="preq"> 
    <tbody> 
     <tr> 
    <td> 
    <input title="Enter Kind Of work 4" readonly="readonly" onclick="if(this.value!=''){this.value='';opendrop();}else{opendrop();}" id="other_work4" name="other_work4" type="text" size="30" <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_work4']).'"'; } ?> >    
    </td> 
    <td><input name="client_name4" size="40" type="text" id="client_name4"/> 
    </td> 
    <td><input name="firm_name4" size="40" type="text" id="firm_name4" /> </td> 
    </tr> 
    </tbody> 
    </table> 

    <input type='button' value='Add Button' id='addButton' /> 

    </body> 
    </html> 
+1

可能的重複http://stackoverflow.com/questions/2160890/how-do-you-append-rows-to-a-table-using-jquery&http://stackoverflow.com/questions/2228772/動態添加刪除行在表中使用jQuery的& –

回答

2

這裏是answer你的問題。

$("#preq tbody").append('<tr id="row"><td></td><td></td><td></td></tr>'); 

看看這個演示,這可能會幫助你添加表中的行。看看這個JQFAQ.com,還有更多的常見問題,我希望這可以幫助你獲得更多的想法。