Many scenes will be encountered on the Web page, users like to use Excel, directly to the HTML table content to operate, so write a convenient use of plug-ins
CSDN Download Address: http://download.csdn.net/detail/w172087242/9589681
Upgrade Download Address
Here is the JavaScript code:
/*** * Function: Make the read-only form editable table * Support custom event for Edit * table style can be set by itself * Only responsible for TBODY section * Data structure style is as follows: {rows:3, data:[{name: "Litt Lehow ", age:18},{...}], column:[" name "," Age "} * @author Littlehow * @time 2016/7/29 Friday **/(function () {var $
= function (node) {return typeof node = = "string"? document.getElementById (node): node;
var $ = function (node, parent) {var nd = document.createelement (node);
if (parent) parent.appendchild (ND);
return nd; /** bound Event Stream/var bind = function (obj, eventName, funcionname) {if (Obj.addeventlistener) {Obj.addeventlistener (eve
Ntname, Funcionname,false);
}else if (obj.attachevent) {obj.attachevent ("on" + EventName, funcionname);
}else{obj["on" + eventName] = Funcionname;
}
};
var fulltable = function (tbody, data) {var PD = Data.data;
var column = Data.column;
For (Var i=0, len=data.rows i<len; i++) {var tr = $ ("tr", tbody);
var cd = Pd[i]; for (Var j=0,jlen=column.length j<jlen; J + +) {VAR td = $ ("TD", TR); td.innerhtml = Cd[column[j]];//innertext is not compatible with Firefox, you can write their own innertext and textcontent compatible, here directly with the InnerHTML}} var littlehow_ed
it_table = function (tbody, ev) {this.tbody = $ (tbody); this.event = EV?
EV: "click";/the default is a stand-alone event This.init = function (data) {//data can be undefined if (data) {fulltable (this.tbody, data);
//Call editable This.edit ();
} This.edit = function () {var TDS = This.tbody.getElementsByTagName ("TD");
for (var i=0,len=tds.length; i<len; i++) {bind (tds[i), this.event, This.click);
} This.click = function () {//alert (this.children.length);
if (This.children.length > 0) return;
var v = this.innerhtml;
this.innerhtml = "";
var input = $ ("input", this);
Input.type = "text";
Input.value = v;
Input.focus ()//Cursor aggregation bind (input, "blur", Blur);
var blur = function () {var v = this.value;
This.parentNode.innerHTML = v; } window.$$ = function (ID, EV) {return new littlehow_edit_table (ID, EV);
}; })()
If you want to call, you can download the channel download.