Informasi yang diakumulasikan untuk formulir input dinamis berikutnya sangat bagus. Biarkan saya membaginya dengan Anda untuk referensi Anda. Jika ada plug-in dan enkapsulasi yang lebih baik, silakan bagikan. .
Kode kuncinya adalah sebagai berikut:
<script type = "text/javascript"> var currentActiveVerow; // warna yang dipilih var customtable = function () {}; customtable.prototype = {init: {ajaxUrl: "", tid: "tbody", delmsg: "Konfirmasi untuk menghapusnya?"}, Ajax: function (params, callback) {var that = this; $. Ajax ({type: "fies:" get, "callback) {var that = this; $. Ajax ({{type:" fies: "get," get, "get," get, "get," get, "get," get, "get," get, "get," get, " itu argumen [1] || function () {}, kesalahan: argumen [2] || "getBookBag", acak: math.random ()}; var suc = function (data) {if (data.issuccess === 1) {} else {}}; var err = function () {}; ttable.ajax (params, suc, err);}, addrow: function () {varown. = tbody.rows.length; tbody.insertrow (rowno); tbody.rows [rowno] .insertcell (0); tbody.rows [rowno] .cells [0] .AppendChild (document.createTextNode (rowno + 1)); // Innertext = "0001"; // Innertext dan Innerhtmltbody.rows [rowno] .Insertcell (1); tbody.rows [rowno] .cells [1] .innerhtml = "<input name = 'Radiorms' Type = 'Radio' value = '1'> </input> "; tbody.rows [rowno] .insertcell (2); tbody.rows [rowno] .cells [2] .innerHtml =" <input name = 'checkboxrms' type = 'centang kotak centang' value = '1'> </input> "; tbody.rows [rowno] .insertcell (3); tbody.rows [rowno] .cells [3] .innerhtml =" <input name = 'deskrip "'> </input>"; tbody.rows [rowno] .insertcell (4); tbody.rows [rowno] .cells [4] .innerHtml = "<input type =' Tombol 'value =' hapus 'onclick =' ttable.deleterow (event) '/> <input type =' kumpulan = 'edite.deleterow (event)'/> <input type = 'kumpulan =' edit ' OnClick = 'ttable.Editrow (event)'/> <a href = 'javascript: void (0)' onClick = 'ttable.moveup (this)'> ↑ </a> <a href = 'javascript: void (0)' onclick = 'ttable.moverown (ini)'> etakan 'etakan' etakan (0) '; ttable.ChangeacTiverow;}, deleterow: function (eve) {if (konfirmasi (this.init.delmsg)) {element = window.event? window.event.srcelement: eve.target; var rowno = element.parentnode.parentnode.rowIndex; var tbody = document.geteLementById (this.init.tid); tbody.deleterow (rowno - 1);}, editrow: function () {var element = window.event? window.event.srcelement: eve.target; alert (elemen);}, changeactverow: function () {// atur warna latar belakang dari baris baris yang dipilih = argumen [0]; elemen = window.event? window.event.srcelement: eve.target; obj = element.parentnode; while (obj && obj.tagname! = "tr") {obj = obj.parentnode; if (currentActiveRow) currentactiverow.style.backgroundsolor = ""; currentactiverowow = obj; lancar; "Merah";}}, cleanwhitespace: function (element) {// ketenangan melalui node anak elemen untuk (var i = 0; i <element.childnodes.length; i ++) {var node = element.childnodes [i]; if (node.nodetype == 3 &&&& & ! // s/.test (node.nodue)) node.parentnode.removechild (node);} // pindahkan tabel row ke atas dan terima parameter sebagai objek tautan}, moveup: function (_a) {var _table = document.geteLementById (this.init.tid); ttable. _a.parentnode.parentnode; var _row = currentActiverow; // Jika itu bukan urutan pertukaran baris pertama jika (_row.previoussibling) ttable.swapnode (_row, _row.previoussibling);}, pindahkan: fungsi (_a) {var _table = document.geteLementById (this.init.tid); ttable.cleanwhitespace (_table); // Dapatkan referensi baris tabel melalui objek tautan // var _row = _a.parentnode.parentnode; var _row = currentActiverow; // Jika itu bukan baris terakhir, row if _row = var nex (_row.nextsibling) ttable.swapnode (_row, _row.nextsibling);}, swapnode: function (node1, node2) {var _parent = node1.parentNode; var _t1 = node1.nextSibling; var _t2 = node2.next1 = node1.nextsibling; var _t2 = node2. (_t1) _parent.insertbefore (node2, _t1); else_parent.applchild (node2); // masukkan node1 ke posisi ndoe2 asli if (_t2) _parent.insertBefore (node1, _t2); else_parent.applapdchild (node1); node1, node1, _t2); else_parent.appendChild (node1 (node1; customtable (); </script>Di antara mereka:
<Table ID = "Tabungan"> <thead id = "head"> <tr onclick = "ttable.changeactverow (this);"> <td> nomor seri </td> <td> default </td> <td> </td </td </td> <t/td </td/td </td/td </td/td </td/td </td/td </td/td </td/td </td/td </td> <it/ id = "tbody"> </tbody> </able> <tombol onclick = "ttable.addrow ()" value = "add"> Tambahkan </button> <tombol onclick = "ttable.movedown ()" value = "add"> ↓ </button>
Di atas adalah deskripsi lengkap dari kode implementasi tabel pembuatan otomatis yang dienkapsulasi JS yang diperkenalkan kepada Anda oleh editor. Saya harap ini akan membantu Anda. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas Anda tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!