AJAX Imitation Excel table function _javascript skills

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "http://www.w3c.org/TR/1999/REC-html401-19991224/ Loose.dtd "> <!--saved from Url= (0041) http://fslh.wisea.cn/mysoft/sim_excel.htm--> ><TITLE> Imitation Excel table demo </TITLE> <meta http-equiv=content-type content= "text/html; charset=gb2312 "> <meta http-equiv=msthemecompatible content=no> <script type=text/javascript>/////// Variable-Initialize///////////////////////////////////////var tobecolor = "#F8F9FC"; var BackColor = "#FFFFFF"; var tableId = "Tbdata"; var table; var tbody; var divshowinput; Window.onload=function () {Beginlisten (); Table = document.getElementById (tableId); Tbody = Table.getelementsbytagname ("tbody") [0]; Actionfill (); Otherfill (); Creatdiv (); Divshowinput = document.getElementById ("Divshowinput"); function Creatdiv () {var filldiv = document.createelement ("div"); Filldiv.setattribute ("id", "divshowinput"); var barp = document.createelement ("P"); Barp.setattribute ("id", "bartitle"); Barp.onclick=hidediv; var defcomp = document.createelement ("P"); Defcomp.setattribute ("id", "Defcomp"); Defcomp.onclick=hidediv; var Cleara = document.createelement ("a"); Cleara.setattribute ("href", "javascript:void 0"); Cleara.onclick=clearinput; var clearatext = document.createTextNode ("Empty"); Cleara.appendchild (Clearatext); Defcomp.appendchild (Cleara); var autop = document.createelement ("P"); Autop.setattribute ("id", "AUTOFILLP"); Filldiv.appendchild (BARP); Filldiv.appendchild (Defcomp); Filldiv.appendchild (Autop); Document.body.appendChild (FILLDIV); //////////////////////////////////////////variable-_ initialization//////////////////////////////////////////////////////////// Action Fill///////////////////////////////////////function Actionfill () {var dbinputs = Tbody.getelementsbytagname ("input"); for (var i = 1;i<=dbinputs.length-1;i++) {dbinputs[i].onfocus=stoplisten; Dbinputs[i].Onblur=beginlisten; Dbinputs[i].ondblclick=showdiv; Dbinputs[i].onmouseover=onchangtrcolor; Dbinputs[i].onmouseout=outchangtrcolor; Dbinputs[i].onclick=readyedit; Dbinputs[i].onkeydown=gonext; The function Otherfill () {var bt_selectall = document.getElementById ("Bt_selectall"); Bt_selectall.setattribute ("href", "javascript:void 0"); Bt_selectall.onclick=selectall; var bt_delselect = document.getElementById ("Bt_delselect"); Bt_delselect.setattribute ("href", "javascript:void 0"); Bt_delselect.onclick=delselect; var bt_copyselect = document.getElementById ("Bt_copyselect"); Bt_copyselect.setattribute ("href", "javascript:void 0"); Bt_copyselect.onclick=copyselect; var bt_allclear = document.getElementById ("Bt_allclear"); Bt_allclear.setattribute ("href", "javascript:void 0"); Bt_allclear.onclick=allclear; var bt_senddata = document.getElementById ("Bt_senddata"); Bt_senddata.setattribute ("href", "javascript:void 0"); Bt_senddata.onclick=senddata; } ///////////////////////Action Filler/////////////////////////////////////////////////////////////////////////////////ajax class/ function Ajax (URL,RECVT,STRINGS,RESULTF) {this.url = URL; This.strings = StringS; This.xmlhttp = This.createxmlhttprequest (); THIS.RESULTF = RESULTF; THIS.RECVT = RECVT; if (this.xmlhttp = = null) {alert ("Erro"); Return var objxml = this.xmlhttp; var othis = this; Objxml.onreadystatechange = function () {othis.handlestatechange ()}; } Ajax.prototype = {createxmlhttprequest:function () {try {return new ActiveXObject ("Msxml2.xmlhttp");} catch (e) {} try {return new ActiveXObject ("Microsoft.XMLHTTP"); \ catch (e) {} try {return new XMLHttpRequest ();} catch (E) {} ret Urn null; }, Createquerystring:function () {var querystring = this.strings; return querystring; }, Get:function () {url = this.url; var querystring = url+ "? timestamp=" + New Date (). GetTime () + "&" + this.createquerystring (); This.xmlhttp. Open ("Get", querystring,true); This.xmlHttp.send (NULL); }, Post:function () {url = this.url; var url = url + "? timestamp=" + New Date (). GetTime (); var querystring = this.createquerystring (); This.xmlHttp.open ("POST", url,true); This.xmlHttp.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); This.xmlHttp.send (querystring); }, Handlestatechange:function () {var xmlhttp = this.xmlhttp; var recvt = this.recvt; var RESULTF = THIS.RESULTF; if (xmlhttp.readystate = = 4) {if (Xmlhttp.status = =) {Resultf.call (this,recvt?xmlhttp.responsexml:xmlhttp.response Text); else {alert ("the page you requested has an exception. "); //////////////////////////////////////////ajax class//////////////////////////////////////////////////////////// Handling Mouse events/////////////////////////////////////////table discoloration function Onchangtrcolor (event) {var E = Eve NT | | window.event; var obj = E.target | | E.srcelement; Obj.parentNode.style.backgroundColor = Tobecolor; Obj.style.BackgroundColor = Tobecolor; var inputs = Obj.parentNode.parentNode.getElementsByTagName ("input"); for (var i = 0; i < inputs.length i++) {inputs[i].style.backgroundcolor = Tobecolor; Inputs[i].parentnode.style.backgroundcolor = Tobecolor; } function Outchangtrcolor (event) {var e = event | | window.event; var obj = E.target | | E.srcelement; Obj.parentNode.style.backgroundColor = BackColor; Obj.style.backgroundColor = BackColor; var inputs = Obj.parentNode.parentNode.getElementsByTagName ("input"); for (var i = 0; i < inputs.length i++) {inputs[i].style.backgroundcolor = BackColor; Inputs[i].parentnode.style.backgroundcolor = BackColor; }//////////////////////////////////////////handles mouse events///////////////////////////////////////////////////////////// Process page Operations/////////////////////////////////////////Copy selected function Copyselect () {var checkboxs = Document.getelementsbyname ("checkbox"); for (var i=0; i<checkboxs.length; i++) {if checkboxs[i].checked = = true) {checkboxs[i].checked = false; COPYTR (Checkboxs[i]); Checkboxs[i].checked = true; } actionfill (); function Copytr (obj) {var tbody = document.getElementById ("Tbdata"). getElementsByTagName ("tbody") [0]; var Str = Obj.parentNode.parentNode; var tr = Str.clonenode (true); Tbody.appendchild (TR); //Delete the selected function Delselect () {var checkboxs = document.getelementsbyname ("checkbox"); var tr = table.getelementsbytagname ("tr"); for (var i=0; i<checkboxs.length; i++) {if (tr.length==2) {checkboxs[i].checked = false; Return } if (checkboxs[i].checked==true) {removetr (checkboxs[i]); I=-1; }} function Removetr (obj) {var sTr = Obj.parentNode.parentNode; STr.parentNode.removeChild (STR); //All Select button function SelectAll () {var checkboxs = document.getelementsbyname ("checkbox"); var mark = true; For (Var i=0. i<checkboxs.length; i++) {if (checkboxs[i].checked==false) {mark = false}} if (Mark) {for (Var i=0; i<checkboxs.length;i++) {checkboxs[i].checked = false; }}else{for (var i=0; i<checkboxs.length; i++) {checkboxs[i].checked = true; //mouse click Focus function Readyedit (event) {var e = event | | window.event; var obj = E.target | | E.srcelement; Obj.select (); }//Empty function AllClear () {var inputs = Tbody.getelementsbytagname ("input"); for (Var i=0;i<inputs.length;i++) {inputs[i].value= ""; }///delete all function Alldel () {var TRS = Tbody.getelementsbytagname ("tr"); alert (trs.length); for (var i=1 i<=trs.length; i++) {if (typeof (Trs[i))!= "undefined") {Tbody.removechild (trs[i)); i=0; //////////////////////////////////////////handles page Operations//////////////////////////////////////////////////////////// Handling keyboard Actions/////////////////////////////////////////keyboard event function Beginlisten () {if ( Document.addeventlistener) {Document.addeventlistener ("KeyDown", keydown,true); }else{document.attachevent ("onkeydown", KeyDown); }} function Stoplisten () {if (docuMent.removeeventlistener) {Document.removeeventlistener ("KeyDown", keydown,true); }else{document.detachevent ("onkeydown", KeyDown); }///Handle keyboard event function KeyDown (event) {var e = event | | window.event; if (e.keycode==45) {ADDTR ()} if (e.keycode==46) {deltr ()}}//Add Table function Addtr () {var sTr = Tbody.getelementsbytagnam E ("tr") [0]; var tr = Str.clonenode (true); Tbody.appendchild (TR); Actionfill (); //Delete table function deltr () {var tr = table.getelementsbytagname ("tr"); if (tr.length==2) {return;} var lasttr = tr[tr.length-1]; LastTr.parentNode.removeChild (LASTTR); }//Move focus function GoNext (event) {var e = event | | window.event; var obj = E.target | | E.srcelement; if (e.keycode==13) {var nextobj = obj.parentNode.parentNode.nextSibling; var objindex = Obj.parentNode.cellIndex; if (nextobj) {if (nextobj.nodetype==3) {var nextinput = nextobj.nextSibling.getElementsByTagName ("input") [Objindex]; Nextinput.focus (); Nextinput.select (); }else{var nextinput = NextobJ.getelementsbytagname ("input") [Objindex]; Nextinput.focus (); Nextinput.select (); //////////////////////////////////////////handles keyboard operations/////////////////////////////////////////////////////////// Handle button Events/////////////////////////////////////////automatically populate Var currentobj; function Showdiv (event) {var e = event | | window.event; var obj = E.target | | E.srcelement; var EX = E.clientx; var EY = E.clienty; var SY = Document.body.parentNode.scrollTop; var DY = EY + SY; var divshowinput = document.getElementById ("Divshowinput"); DivShowInput.style.top = DY + "px"; DivShowInput.style.left = ex+ "px"; DivShowInput.style.display = "block"; Hidelisten (); CurrentObj = obj; Intelligent Menu////fixmenu (); To judge the focus position var tdorder = Obj.parentNode.cellIndex; Fill title title var Tdtitletr = document.getElementById ("Tbdata"). getElementsByTagName ("tr") [0]; var tdtitle = tdtitletr.getelementsbytagname ("TD") [Tdorder]; document.getElementById ("Bartitle"). InnerHTML = Tdtitle.innerhtml; Collect form information//Judge repeat var TRS = obj.parentNode.parentNode.parentNode.getElementsByTagName ("tr"); var AUTOFILLP = document.getElementById ("AUTOFILLP"); var BANKM = true; for (var i = 0; i < trs.length i++) {var inputvalue = Trs[i].getelementsbytagname ("TD") [Tdorder].getelementsbytagnam E ("input") [0].value; if (Inputvalue!= "") {BANKM = false; var menus = autofillp.getelementsbytagname ("a"); if (Menus.length > 0) {var belivem = true; for (var j = 0; J < Menus.length; J +) {if (Menus[j].firstchild.nodevalue = = inputvalue) {Belivem = false; } if (Belivem) {var svalue = document.createelement ("a"); Svalue.setattribute ("href", "javascript:void 0"); Svalue.onclick = function () {fillinput (this)}; var stext = document.createTextNode (Inputvalue); Svalue.appendchild (stext); Autofillp.appendchild (svalue); }}else{var svalue = document.createelement ("a"); Svalue.setattribute ("href", "javascript:void 0"); Svalue.onclick = function () {fillinput (this)}; Var Stext = document.createTextNode (Inputvalue); Svalue.appendchild (stext); Autofillp.appendchild (svalue); }} if (BANKM) {var svalue = document.createelement ("a"); Svalue.setattribute ("href", "javascript:void 0"); var stext = document.createtextnode ("Data null"); Svalue.appendchild (stext); Autofillp.appendchild (svalue); } function Fillinput (obj) {currentobj.value = obj.innerhtml; DivShowInput.style.display = "None"; function Clearinput () {currentobj.value = ""; DivShowInput.style.display = "None"; function Hidediv () {divShowInput.style.display = ' none '; Stophide (); function Hidelisten () {if (Document.addeventlistener) {Document.addeventlistener ("click", Hidediv,true); }else{document.attachevent ("onclick", hidediv); }} function Stophide () {if (Document.removeeventlistener) {Document.removeeventlistener ("click", Keydown,true); }else{document.detachevent ("onclick", KeyDown); }//Delete smart Menu existing data function fixmenu () {var AUTOFILLP = Document.getelemenTbyid ("AUTOFILLP"); var values = Autofillp.getelementsbytagname ("a"); for (var i = values.length-1 i >= 0; i--) {autofillp.removechild (values[i]); }//////////////////////////////////////////handles button events///////////////////////////////////////////////////////////// Data send/////////////////////////////////////////////////////////////////////////////////data Send/ function SendData () {var divfoltupdiv = document.getElementById ("Divfoltupdiv "); DivFoltupDiv.style.display = "block"; var sendokinf = document.getElementById ("Sendokinf"); var sendokbiginf = document.getElementById ("Sendokbiginf"); var sendname = new Array (); var trs = Tbody.getelementsbytagname ("tr"); var inputnames = trs[0].getelementsbytagname ("input"); for (var i = 0; i < inputnames.length-1 i++) {sendname[i]=inputnames[i+1].getattribute ("name"); var trnum = trs.length; var oknum = 0; for (var i = 0; i < trnum i++) {var values = TRS[I].GEtelementsbytagname ("input"); var poststringary = new Array (); for (var j = 0; J < Values.length-1; J + +) {poststringary[j]=sendname[j]+ "=" +values[j+1].value; var poststring = Poststringary.join ("&"); function Sendok (revdata) {if (revdata== "OK") {oknum++; sendokinf.innerhtml = "+oknum+" has been successfully sent +trnum+ "line"; sendokbiginf.innerhtml = Trnum-oknum; if (trnum-oknum==0) {divFoltupDiv.style.display = "none"; AllClear (); Alldel (); }} var Sendajax = new Ajax ("isave.asp", 0,poststring,sendok); Sendajax.post (); }//////////////////////////////////////////Data send/////////////////////////////////////////--> </SCRIPT> <style Type=text/css>body {font-size:12px; Font-family:arial, Helvetica, Sans-serif; Background-color: #e9edf7} #tbBackground {background-color: #ffffff; Text-align:center} #tbData {background-color: #dde3ec} #tbData TD {background-color: #ffffff} #tbData INPUT {width:50px; Border-top-style:none; Border-rigHt-style:none; Border-left-style:none; Border-bottom-style:none} #tbData. checkbox {width:15px} #tbData THEAD {} #tbTopOpt A {border-right: #99999 9 1px solid; padding-right:5px; Border-top: #999999 1px solid; Display:block; padding-left:5px; padding-bottom:5px; Border-left: #999999 1px solid; width:80px; COLOR: #000000; padding-top:5px; Border-bottom: #999999 1px solid; Background-color: #f8f9fc; Text-decoration:none} #tbTopOpt a:hover {background-color: #dde3ec} #tbBomOpt A {border-right: #999999 1px soli D padding-right:5px; Border-top: #999999 1px solid; Display:block; padding-left:5px; padding-bottom:5px; Border-left: #999999 1px solid; width:80px; COLOR: #000000; padding-top:5px; Border-bottom: #999999 1px solid; Background-color: #f8f9fc; Text-decoration:none} #tbBomOpt a:hover {background-color: #dde3ec} #tbData A {COLOR: #000000; Text-decoration:none} #divShowInput {border-right: #dde3ec 1px solid; Border-top: #dde3ec 1px Solid Display:none; Z-index:10; left:350px; Overflow:hidden; Border-left: #dde3ec 1px solid; width:100px; Border-bottom: #dde3ec 1px solid; Position:absolute; top:30px; Background-color: #f8f9fc} #divShowInput A {display:block; Width:auto; COLOR: #000000; Background-color: #f8f9fc; Text-align:center; Text-decoration:none} #divShowInput a:hover {border-right: #ff0000 2px solid; Border-left: #ff0000 2px solid; COLOR: #ff0000; Background-color: #dde3ec} #divShowInput P {padding-right:0px; padding-left:0px; Border-bottom-color: #dde3ec; padding-bottom:0px; margin:0px; padding-top:0px; Background-color: #f8f9fc; Text-align:center; Border-bottom-style:double} #divFoltupDiv {display:none; z-index:1001; right:0px; FILTER:progid:DXImageTransform.Microsoft.AlphaImageLoader (Enabled=true, Sizingmethod=scale, src= ' gb.png '); left:0px; padding-bottom:300px; width:100%; bottom:0px; padding-top:270px; Position:absolute; top:0px; Text-align:center}UNKNOWN {background-image:url (gb.png); Background-repeat:repeat} p#sendokbiginf {font-size:20px; color:red} </STYLE> <meta content= "MSHTML 6.00.2800.1400" name=generator></pead> <BODY> ;D IV id=divfoltupdiv> <p> Send data </P> <p id=sendokbiginf> </p > <p id=sendokinf> </p></div> <table id=tbbackground cellspacing=0 cellPadding=0 width= 760 align=center border=0> <TBODY> <TR> <TD> </TD></TR> <TR> <TD> <table id=tbdata cellspacing=1 cellpadding=0 width=750 align=center border=0> <THEAD> <TR> <TD H eight=25> all options </TD> <TD>A1</TD> <TD>A2</TD> <TD>A3</TD> <TD>A4< /TD> <TD>A5</TD> <TD>A6</TD> <TD>A7</TD> <TD>A8</TD> <TD> A9</td> <TD>A10</TD> &LT;TD&GT;A11</td></tr></thead> <TBODY> <TR> <td><input class=checkbox Type=checkbox Value=checkbox name=checkbox></td> <td><input name=a1></td> <TD><INPUT name=A2 ></TD> <td><input name=a3></td> <td><input name=a4></td> <TD> <input name=a5></td> <td><input name=a6></td> <td><input Name=A7></TD > <td><input name=a8></td> <td><input name=a9></td> <TD><INPUT name= A10></td> <td><input name=a11></td></tr></tbody></table></td> </TR> <TR> <TD> <table id=tbbomopt cellspacing=0 cellpadding=0 width=700 align=center border=0&gt ; <TBODY> <TR> <td width=125 height=40> Copy selected </TD> <td width=537> Delete selected </TD> <td Widt h=537> empty All </TD> <td width=537> Submit </td> &LT;TD width=38> </td></tr></tbody></table></td></tr></tbody> </TABLE> <HR> Action Method one keyboard to operate the 1.Insert key to add a row, and copy the last line of content, delete deletes the last row, the operation to adjust the total size of the table; 2.Tab keys move the cursor horizontally, the ENTER key moves the cursor vertically, Conform to excle user habits; two page operation 1. Select all: Selects all rows, executes the release all rows again; 2. Copy selected: Copy the selected row and its contents; 3. Delete selected: Delete The row that you have selected; 4. Clear all cells (input) and 5. Submit: Send data content to server three smart actions double-click a cell to bring up the menu, which automatically collects all the content that is not duplicated on the column, and facilitates the repeated input of the data. </BODY></HTML>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.