AJAX 仿EXCEL表格功能
仿Excel表格演示
//////////////////////////////////////////变量—初始化///////////////////////////////////////
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("清空");
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);
}
//////////////////////////////////////////变量—_初始化///////////////////////////////////////
//////////////////////////////////////////动作填充///////////////////////////////////////
function actionFill (){
var dbinputs = tbody.getElementsByTagName("input");
for (var i = 1;i 0) {
var beliveM = true;
for (var j = 0; j = 0; i-- ){
autoFillP.removeChild(values[i]);
}
}
//////////////////////////////////////////处理按钮事件///////////////////////////////////////
//////////////////////////////////////////数据发送///////////////////////////////////////
//////////////////////////////////////////数据发送///////////////////////////////////////
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
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: #999999 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 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
}
#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
}
发送数据
| ||||||||||||||||||||||||
|
操作方法
一
键盘操作
1.Insert键增加一行,并复制最后一行内容,Delete键删除最后一行,该操作用以调节表格总大小;
2.Tab键横向移动光标,Enter键纵向移动光标,符合Excle用户习惯;
二
页面操作
1.全选:选择全部行,再次执行释放全部行;
2.复制所选:复制已经选择的行及其内容;
3.删除所选:删除已经选择的行;
4.清空所选:清除所有单元格(input)中的内容;
5.提交:发送数据内容到服务器
三
智能操作
双击单元格将弹出菜单,菜单自动收集该列上所有不重复的已输入内容,为重复输入数据提供了方便。
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]