My idea is this: 1. For any table, tr, you can add editing and deletion functions - the functions are independent 2. You can automatically complete the editing and cancellation functions, such as clicking edit, the table content will automatically It becomes an edit box, drop-down box, etc., click Cancel to end the editing state 3. Add deletion and confirmation (i.e. update) events - just add your own server-side deletion and update code 4. Ability to customize Set editable columns and non-editable columns - to facilitate customized editing functions
The following is the function code I implemented: editable.js
/* code: editable.js version: v1.0 date: 2011/10/21 author: lyroge@foxmail.com usage: $("table").editable({ selector can select table or tr head: true, whether there is a title noeditcol: [1, 0], which columns cannot be edited Edit column configuration: colindex: column index edittype: element displayed during editing 0: input 1: checkbox 2: select ctrid: id of the associated element If edittype=2, then you need to set the select element css: element Style editcol: [{ colindex: 2, edittype: 2, ctrid: "sel",css:""}], onok: function () { return true; Return true or false according to the result }, ondel: function () { return true; returns true or false according to the result } }); */ (function ($) { $.fn.editable = function (options) { options = options || {}; opt = $.extend({}, $.fn.editable.defaults, options); trs = []; $.each(this, function () { if (this.tagName.toString().toLowerCase() == "table") { $(this). find("tr").each(function () { trs.push(this); }); } else if (this.tagName.toString().toLowerCase() == "tr") { trs.push(this); } }); $trs = $(trs); if ($trs.size() = = 0 || (opt.head && $trs.size() == 1)) return false; var button = "
$(function () { $("table").editable({ head: true, //테이블 헤더가 있습니다 noeditcol: [0] , //첫 번째 열은 편집할 수 없습니다 editcol: [{ colindex: 1 }, { colindex: 2, edittype: 2, ctrid: "sel"}], //테이블의 편집 열 구성 ctrid: 연관된 dom 요소 ID입니다 onok: function () { return false; //false를 반환하면 실패를 나타내며 dom 요소는 변경되지 않습니다. }, ondel: function() { return true; //성공을 나타내려면 false를 반환합니다. } }) });
3. 편집 효과 추가
참고: 편집 기능에서 여러 버튼 스타일을 구성할 수도 있습니다. 자세한 내용은 코드를 참조하세요.) 파일 소스 코드:
editable.rar
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn