Author llinzzi
Version 0.9
Note:
When the focus is not on the input in the table, press the Enter key to copy the last row, and the Delete key to copy the last row
Select the checkbox to copy and delete
Double-click the table and a menu will appear to automatically collect the existing data in the column. Select AutoFill. Here are the highlights
Data is sent using ajax (a custom ajax class, which has been published on the blog) row by row.
Compatible with IE6 and Firefox1.5 complies with W3C
All functions of this form are to reduce input input work and are suitable for open use in large projects
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script> <BR><!-- <BR>//////////////////////////////////////////页面初始化/////////////////////////////////////// <BR>beginListen(); <BR>//////////////////////////////////////////页面初始化/////////////////////////////////////// <BR>//////////////////////////////////////////ajax类/////////////////////////////////////// <BR>function Ajax(url,recvT,stringS,resultF) { <BR> this.url = url; <BR> this.stringS = stringS; <BR> this.xmlHttp = this.createXMLHttpRequest(); <BR> if (this.xmlHttp == null) { <BR> alert("erro"); <BR> return; <BR> } <BR> var objxml = this.xmlHttp; <BR> objxml.onreadystatechange = function (){Ajax.handleStateChange(objxml,recvT,resultF)}; <BR>} <br><br>Ajax.prototype.createXMLHttpRequest = function() { <BR> try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} <BR> try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} <BR> try { return new XMLHttpRequest(); } catch(e) {} <BR> return null; <BR>} <br><br>Ajax.prototype.createQueryString = function () { <BR> var queryString = this.stringS; <BR> return queryString; <BR>} <br><br>Ajax.prototype.get = function () { <BR> url = this.url; <BR> var queryString = url "?timeStamp=" new Date().getTime() "&" this.createQueryString(); <BR> this.xmlHttp.open("GET",queryString,true); <BR> this.xmlHttp.send(null); <BR>} <br><br>Ajax.prototype.post = function() { <BR> url = this.url; <BR> var url = url "?timeStamp=" new Date().getTime(); <BR> var queryString = this.createQueryString(); <BR> this.xmlHttp.open("POST",url,true); <BR> this.xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); <BR> this.xmlHttp.send(queryString); <BR>} <br><br>Ajax.handleStateChange = function (xmlHttp,recvT,resultF) { <BR> if (xmlHttp.readyState == 4) { <BR> if (xmlHttp.status == 200) { <BR> resultF(recvT?xmlHttp.responseXML:xmlHttp.responseText); <BR> } else { <BR> alert("您所请求的页面有异常。"); <BR> } <BR> } <BR>} <BR>//////////////////////////////////////////ajax类/////////////////////////////////////// <br><br>//////////////////////////////////////////处理鼠标事件/////////////////////////////////////// <BR>//表格变色 <BR>var toBeColor = "#F8F9FC"; <BR>var backColor = "#FFFFFF"; <BR>function onChangTrColor(obj) { <BR> obj.parentNode.style.backgroundColor = toBeColor; <BR> obj.style.backgroundColor = toBeColor; <BR> var inputs = obj.parentNode.parentNode.getElementsByTagName("input"); <BR> for (var i = 0; i < inputs.length; i ){ <BR> inputs[i].style.backgroundColor = toBeColor; <BR> inputs[i].parentNode.style.backgroundColor = toBeColor; <BR> } <BR>} <br><br>function outChangTrColor(obj) { <BR> obj.parentNode.style.backgroundColor = backColor; <BR> obj.style.backgroundColor = backColor; <BR> var inputs = obj.parentNode.parentNode.getElementsByTagName("input"); <BR> for (var i = 0; i < inputs.length; i ){ <BR> inputs[i].style.backgroundColor = backColor; <BR> inputs[i].parentNode.style.backgroundColor = backColor; <BR> } <BR>} <br><br>//////////////////////////////////////////处理鼠标事件/////////////////////////////////////// <br><br>//////////////////////////////////////////处理页面操作/////////////////////////////////////// <BR>//复制所选 <BR>function copySelect(){ <BR> var checkboxs = document.getElementsByName("checkbox"); <BR> for (var i=0; i<checkboxs.length; i ) { <BR> if(checkboxs[i].checked == true){ <BR> checkboxs[i].checked = false; <BR> copyTr(checkboxs[i]); <BR> checkboxs[i].checked = true; <BR> } <BR> } <BR>} <br><br>function copyTr(obj) { <BR> var tbody = document.getElementById("tbData").getElementsByTagName("tbody")[0]; <BR> var Str = obj.parentNode.parentNode; <BR> var tr = Str.cloneNode(true); <BR> tbody.appendChild(tr); <BR>} <br><br>//删除所选 <BR>function delSelect(){ <BR> var checkboxs = document.getElementsByName("checkbox"); <BR> var table = document.getElementById("tbData"); <BR> var tr = table.getElementsByTagName("tr"); <BR> for (var i=0; i<checkboxs.length; i ) { <BR> if(tr.length==2){ <BR> checkboxs[i].checked = false; <BR> return; <BR> } <BR> if(checkboxs[i].checked==true){ <BR> removeTr(checkboxs[i]); <BR> i=-1; <BR> } <BR> } <BR>} <br><br>function removeTr(obj) { <BR> var sTr = obj.parentNode.parentNode; <BR> sTr.parentNode.removeChild(sTr); <BR>} <br><br>//全选按钮 <BR>function selectAll() { <BR> var checkboxs = document.getElementsByName("checkbox"); <BR> var mark = true; <BR> for (var i=0; i<checkboxs.length; i ) { <BR> if (checkboxs[i].checked==false){mark = false} <BR> }<BR> if (mark){ <BR> for (var i=0; i<checkboxs.length; i ) { <BR> checkboxs[i].checked = false; <BR> } <BR> }else{ <BR> for (var i=0; i<checkboxs.length; i ) { <BR> checkboxs[i].checked = true; <BR> } <BR> } <BR>} <br><br>// ///////////////////////////////////////////Processing page operations/////// ///////////////////////////////// <br><br>///////////// ////////////////////////////////Handling keyboard operations////////////////// /////////////////////// <BR>//Keyboard events<BR>function beginListen(){ <BR> if(document.addEventListener){ <BR> document.addEventListener("keydown",keyDown,true); <BR> }else{ <BR> document.attachEvent("onkeydown",keyDown); <BR> } <BR>} <BR>function stopListen(){ <BR> document.detachEvent("onkeydown",keyDown); <BR>} <br><br>//Handling keyboard events <BR>function keyDown(event){ <BR> if(event.keyCode==13){ addTr()} <BR> if(event.keyCode==46){delTr()} <BR>} <br><br>//Add table<BR>function addTr() { <BR> var tbody = document .getElementById("tbData").getElementsByTagName("tbody")[0]; <BR> var sTr = tbody.getElementsByTagName("tr")[0]; <BR> var tr = sTr.cloneNode(true); <BR> tbody.appendChild(tr); <BR>} <br><br>//Add table<BR>function addTr() { <BR> var tbody = document.getElementById("tbData").getElementsByTagName("tbody ")[0]; <BR> var trs = tbody.getElementsByTagName("tr"); <BR> var sTr = trs[trs.length-1]; <BR> var tr = sTr.cloneNode(true); <BR> tbody.appendChild(tr); <BR>} <br><br>//Delete table<BR>function delTr() { <BR> var table = document.getElementById("tbData"); <BR> var tr = table.getElementsByTagName("tr"); <BR> if(tr.length==2){return;} <BR> var lastTr = tr[tr.length-1]; <BR> lastTr.parentNode.removeChild (lastTr); <BR>} <br><br><BR>////////////////////////////////// /////////Handling keyboard operations///////////////////////////////////////// / <br><br>/////////////////////////////////////////////Processing Button events //////////////////////////////////////// <BR>//Autofill<BR>var currentObj; <BR>function showDiv(event,obj) { <BR> var eX = event.clientX; <BR> var eY = event.clientY; <BR> var sY = document.body.parentNode.scrollTop; <BR> var dY = eY sY; <BR> var divShowInput = document.getElementById("divShowInput"); <BR> divShowInput.style.top = dY "px"; <BR> divShowInput.style.left = eX "p x" ; <BR> divShowInput.style.display = "block"; <BR> currentObj = obj; <BR> ////Smart Menu//// <BR> fixMenu(); <BR> //Determine the focus position<BR> var tds = obj.parentNode.parentNode.getElementsByTagName("td"); <BR> var tdOrder; <BR> for (var i = 0; i < tds.length; i ){ <BR> if(tds [i] === obj.parentNode){ <BR> tdOrder = i; <BR> } <BR> }<BR> //填充标题标题 <BR> var tdTitleTr = document.getElementById("tbData").getElementsByTagName("tr")[0]; <BR> var tdTitle = tdTitleTr.getElementsByTagName("td")[tdOrder]; <BR> document.getElementById("barTitle").innerHTML = tdTitle.innerHTML; <BR> //收集表格信息//判断重复 <BR> var trs = obj.parentNode.parentNode.parentNode.getElementsByTagName("tr"); <BR> var autoFillP = document.getElementById("autoFillP"); <BR> var bankM = true; <BR> for (var i = 0; i < trs.length; i ){ <BR> var inputValue = trs[i].getElementsByTagName("td")[tdOrder].getElementsByTagName("input")[0].value; <BR> if (inputValue != "") { <BR> bankM = false; <BR> var menus = autoFillP.getElementsByTagName("a"); <BR> if(menus.length > 0) { <BR> var beliveM = true; <BR> for (var j = 0; j < menus.length; j ){ <BR> if(menus[j].firstChild.nodeValue == inputValue) { <BR> beliveM = false; <BR> } <BR> } <BR> if(beliveM){ <BR> var Svalue = document.createElement("a"); <BR> Svalue.setAttribute("href","javascript:void 0"); <BR> Svalue.onclick = function () {fillInput(this)}; <BR> var Stext = document.createTextNode(inputValue); <BR> Svalue.appendChild(Stext); <BR> autoFillP.appendChild(Svalue); <BR> } <BR> }else{ <BR> var Svalue = document.createElement("a"); <BR> Svalue.setAttribute("href","javascript:void 0"); <BR> Svalue.onclick = function () {fillInput(this)}; <BR> var Stext = document.createTextNode(inputValue); <BR> Svalue.appendChild(Stext); <BR> autoFillP.appendChild(Svalue); <BR> } <BR> } <BR> }<BR> if(bankM) { <BR> var Svalue = document.createElement("a"); <BR> Svalue.setAttribute("href","javascript:void 0"); <BR> var Stext = document.createTextNode("数据空"); <BR> Svalue.appendChild(Stext); <BR> autoFillP.appendChild(Svalue); <BR> } <BR>} <br><br>function fillInput(obj) { <BR> currentObj.value = obj.innerHTML; <BR> var divShowInput = document.getElementById("divShowInput"); <BR> divShowInput.style.display = "none"; <BR>} <br><br>function clearInput() { <BR> currentObj.value = ""; <BR> var divShowInput = document.getElementById("divShowInput"); <BR> divShowInput.style.display = "none"; <BR>} <br><br>function hideDiv(obj) { <BR> obj.parentNode.style.display = "none"; <BR>} <br><br>//删除智能菜单已有数据 <BR>function fixMenu() { <BR> var autoFillP = document.getElementById("autoFillP"); <BR> var values = autoFillP.getElementsByTagName("a"); <BR> for (var i = values.length-1; i >= 0; i-- ){ <BR> autoFillP.removeChild(values[i]); <BR> } <BR>} <BR>//////////////////////////////////////////处理按钮事件/////////////////////////////////////// <br><br>//////////////////////////////////////////数据发送/////////////////////////////////////// <br><br>//////////////////////////////////////////数据发送/////////////////////////////////////// <BR>function sendData() { <BR> var sendName = new Array("ok","A1","A2","A3","A4","A5","A6","A7","A8","A9","A10","A11"); <BR> var trs = document.getElementById("tbData").getElementsByTagName("tbody")[0].getElementsByTagName("tr"); <BR> for (var i = 0; i < trs.length; i ) { <BR> var sendValue = new Array(); <BR> var values = trs[i].getElementsByTagName("input"); <BR> var postString = sendName[1] "=" values[1].value;; <BR> for (var j = 2; j < values.length; j ) { <BR> postString = postString "&" sendName[j] "=" values[j].value; <BR> } <BR> var SendAjax = new Ajax("isave.asp",0,postString,sendok); <BR> SendAjax.post(); <BR> function sendok(revData){ <BR> alert(revData); <BR> } <BR> } <BR>} <br><br><br><br>//////////////////////////////////////////数据发送/////////////////////////////////////// <br><br><BR>//--> <BR></script>
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
|

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
