Dynamically add changes to delete HTML table contents

Source: Internet
Author: User

1. Need to add changes to the checkout register Gu Xian can see the changes in real-time when the item is deleted 2. Resolve the cashier and Gu Xian data communication over TCP transmission, Gu Xian add changes and deletions by manipulating the tables in the HTML 3. Code mytest.html
<html><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 "><title>Dynamic Table</title><script type="text/javascript" src="Js/dynamic_table.js"> </script></head><body><table><tr><th>Name</th><th>Color</th><th>Size</th><th>Unit Price</th><th>Discount</th><th>Number</th><th>Amount</th></tr><tbody id="goods"></tbody><tr><TD><input type="button" value="Add" onClick="AddRow (' Colorful 1234 ', ' red ', ' XL ', ' 1000.00 ', ' 1.00 ', ' 1 ', ' 1000.00 ') '/></td><TD><input type="button" value="del" OnClick ="Removerow (' goods ', ' 0 ')"/></td><TD><input type="button" value="Modify" onClick=" Modifyrow (' goods ', ' 0 ', ' 0 ', ' Zhangxiaobao ') ' /></td><TD><input type="button" value="Clear" OnClick ="clearrows (' goods ')"/></td></tr></table></body></html>
Dynamic_table.js
Onerror=handleerrvartxt="" function handleerr(msg,url,l){txt="There are errors on this page. \ n "txt+="Error:"+ msg +"\ n"txt+="URL:"+ URL +"\ n"txt+="line:"+ L +"\ n"txt+="click" OK "to continue. \ n "Alert (TXT)return true} function addRow(name, color, size, unit, discount, count, sum){    varBodyobj=document.getelementbyid ("Goods");if(bodyobj==NULL) {alert ("Body of Table not exist!");return; }varRowCount = BodyObj.rows.length;//var cellcount = myarray.length;    varNewRow = Bodyobj.insertrow (rowcount++); Newrow.insertcell (0). Innerhtml=name; Newrow.insertcell (1). Innerhtml=color; Newrow.insertcell (2). Innerhtml=size; Newrow.insertcell (3). Innerhtml=unit; Newrow.insertcell (4). Innerhtml=discount; Newrow.insertcell (5). Innerhtml=count; Newrow.insertcell (6). Innerhtml=sum;} function removerow(Tbodyid, Row){    varBodyobj=document.getelementbyid (Tbodyid);if(bodyobj==NULL) {alert ("Body of Table not exist!");return; }varNrow = Number(row);if(Nrow <= bodyObj.rows.length) bodyobj.deleterow (nrow);ElseAlert"Nrow is less.");} function modifyrow(Tbodyid, Row, col, NewValue){    varNrow = Number(row);varNcol = Number(COL);varBodyobj=document.getelementbyid (Tbodyid);if(bodyobj==NULL) {alert ("Body of Table not exist!");return; }Try{//var tableobj = Bodyobj.parentnode;        if(Nrow < BodyObj.rows.length && Ncol < Bodyobj.getelementsbytagname (' TR ') [Nrow].getelementsbytagname (' TD '). Length) {//This under IE can not under the Google            //bodyobj.rows (nrow). Cells (ncol). InnerHTML = newvalue;            //bodyobj.rows[nrow].childnodes[ncol].innerhtml = newvalue;            //This can be under IE and Googledocument.getElementById (Tbodyid). getElementsByTagName (' TR ') [Nrow].getelementsbytagname (' TD ') [ncol].innerhtml = newvalue; }ElseAlert"empty."); }Catch(ERR)    {alert (Err.Description); }} function clearrows(Tbodyid){    varBodyobj=document.getelementbyid (Tbodyid);if(bodyobj==NULL) {alert ("Body of Table not exist!");return; } for(vari =0; i < bodyObj.rows.length; ) Bodyobj.deleterow (i);}
Perform normal under Win7 Ie10 and Google 4. Note 1. It is best not to use the Notepad that comes with Windows. There will be coding problems, the recommended use of notepad++, encoded as UTF8 no bom2. Some JS functions are available under IE. Google is not available, this code is generic

Dynamically add changes to delete HTML table contents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.