使用javascript处理HTML表格 [英] Handling the table from a html form with javascript

查看:82
本文介绍了使用javascript处理HTML表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<table id="production">

    <tr>
        <th>Product Name</th>
        <td></td>
        <td>elementsdefined</td>
    </tr>

    <tr>
        <th>Product Name</th>
        <td></td>
        <td>elementsdefined</td>
    </tr>

</table>















产品名称:























产品数量:




























Product Name: Product Quanitity: Add

function updateForm() {

    var prdn = document.getElementById("prodname").value;
    var prdq = document.getElementById("prodquantity").value;
    var table = document.getElementById("production");
    var rows = table.rows;
    var cell1 = rows[0].insertCell(-1);
    var cell2 = rows[1].insertCell(-1);

    cell1.innerHTML = prdn;
    cell2.innerHTML = prdq;

}

我需要某人帮助我了解如何在数据中插入数据数据库中的独立列;假设我有一个三行三列的表,使用td标签创建列,现在在第一列和最后一列中元素是预定义的,所以任何数据都应该在点击按钮后插入表格的第二列。因为上面的代码默认将数据插入到原始单元格中。

I need someone help me understand how I can insert data in separate column in database; suppose I have a table of three rows and three columns, columns are created by using td tags, now in the first and last columns elements are predefined and so any data should insert in the second column of the table after clicking the button. because the code above is inserting the data in raw cells by default.

我在这里添加小提琴
http://jsfiddle.net/3e7rh/2/

推荐答案

http://jsfiddle.net/3e7rh/8/

function updateForm() {
    var prdn = document.getElementById("prodname").value;
   var prdq = document.getElementById("prodquantity").value;
   var table=document.getElementById("production");
   var rows=table.rows;
   var cell1=rows[0].insertCell(rows[0].cells.length - 1);
   var cell2=rows[1].insertCell(rows[1].cells.length - 1);
   cell1.innerHTML=prdn;
   cell2.innerHTML=prdq;
}



更新:



http://jsfiddle.net/3e7rh/10/

function updateForm() {
    var prdn = document.getElementById("prodname").value;
   var prdq = document.getElementById("prodquantity").value;
   var table=document.getElementById("production");
   var rows=table.rows;
   var cell1=rows[0].cells[1].textContent=prdn;
   var cell2=rows[1].cells[1].textContent=prdq;
}

这篇关于使用javascript处理HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆