JavaScript changes the table's TD to editable input, and implements dynamic table editing

Source: Internet
Author: User

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.

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.