関数の実装:
通常、テーブルを編集する場合、一度に追加する行数が多すぎると、このプログラムによるテーブルの応答が遅くなる可能性があります。行を動的に追加でき、常に複数の行を下部に保持します。
効果:
1: オリジナルページ
2: テーブル 1 に新しい行を追加し、タイムピッカーをバインドします
3: テーブル 2 は行を自動的に追加し、新しい行は timepicker にバインドされます
HTML ソース コード:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <link href="../Script/jquery-easyui-1.3.2/themes/default/easyui.css" rel="external nofollow" rel="stylesheet" /> <style> .autoRows{ width: 350px; border:1px green solid; } .autoRows tbody tr td{ border-bottom:1px green solid; margin:0px; } .autoRows thead{ background-color:#8ec7d7; } .autoRows tfoot { background-color: #8ec7d7; } </style> </head> <body> <table border="0" cellspacing="0" id="table1" class="autoRows"> <thead> <tr> <th>表头1</th> <th>表头1</th> <th>表头1</th> </tr> <tr> <th>表头2</th> <th>表头2</th> <th>表头2</th> </tr> </thead> <tbody> <tr> <td> <input id="Button1" type="button" value="insertAfter" onclick="addrow(this);" /></td> <td> <input id="Button3" type="button" value="Clear" onclick="$.fn.tableAutoRow.clearRowData(this, 2, 2, false);" /></td> <td> <input id="Text2" type="text" value="aaaa" /></td> </tr> <tr> <td> <input id="Button2" type="button" value="insertBefore" onclick="$.fn.tableAutoRow.insertRow(this,1,true,false);" /></td> <td> <input id="Button4" type="button" value="Reset" onclick="$.fn.tableAutoRow.clearRowData(this, 2, 2, true);" /></td> <td> <input id="Text1" name="ttt" type="text" value="asdfasfasfdsd" /></td> </tr> <tr> <td> <input id="Button5" type="button" value="insertBefore" onclick="$.fn.tableAutoRow.insertRow(this,1,true,false);" /></td> <td> <input id="Button6" type="button" value="Reset" onclick="$.fn.tableAutoRow.clearRowData(this, 2, 2, true);" /></td> <td> <input id="Text3" type="text" name="Text3" /></td> </tr> </tbody> <tfoot> <tr> <th>表尾1</th> <th>表尾2</th> <th>表尾3</th> </tr> </tfoot> </table> <div style="height:20px;"></div> <table border="0" cellspacing="0" id="table2" class="autoRows"> <thead> <tr> <th>表头1</th> <th>表头1</th> <th>表头1</th> </tr> <tr> <th>表头2</th> <th>表头2</th> <th>表头2</th> </tr> </thead> <tbody> <tr> <td> <input id="Button7" type="button" value="insertAfter" onclick="addrow(this);" /></td> <td> <input id="Button8" type="button" value="Clear" onclick="$.fn.tableAutoRow.clearRowData(this, 2, 2, false);" /></td> <td> <input id="Text4" type="text" value="aaaa" /></td> </tr> <tr> <td> <input id="Button9" type="button" value="insertBefore" onclick="$.fn.tableAutoRow.insertRow(this, 1, true, false);" /></td> <td> <input id="Button10" type="button" value="Reset" onclick="$.fn.tableAutoRow.clearRowData(this, 2, 2, true);" /></td> <td> <input id="Text5" name="ttt" type="text" value="asdfasfasfdsd" /></td> </tr> <tr> <td> <input id="Button11" type="button" value="insertBefore" onclick="$.fn.tableAutoRow.insertRow(this, 1, true, false);" /></td> <td> <input id="Button12" type="button" value="Reset" onclick="$.fn.tableAutoRow.clearRowData(this, 2, 2, true);" /></td> <td> <input id="Text6" type="text" name="Text3" /></td> </tr> </tbody> <tfoot> <tr> <th>表尾1</th> <th>表尾2</th> <th>表尾3</th> </tr> </tfoot> </table> </body> </html> <script src="../Script/jquery-1.7.2.min.js"></script> <script src="../Script/jquery.tableAutoRow.js"></script> <script src="../Script/jquery-easyui-1.3.2/jquery.easyui.min.js"></script> <script src="../Script/jquery.timepicker.js"></script> <script type="text/javascript"> $(function () { $(".autoRows").tableAutoRow(aaa); function aaa(row) { $(row).find(':text').timepicker(); } }); function addrow(obj) { $.fn.tableAutoRow.insertRow(obj); } </script>
JS ソースコード:
/// <reference path="jquery-1.7.2.min.js" /> //为表格主体添加单击事件,当单击时添加行数,使表格保持有n个空行 (function ($) { $.fn.extend({ rowfunction: null, tableAutoRow: function (newRowFunction) { rowfunction = newRowFunction; return $(this).each(function () { var tb = this; if (!(this.tagName.toUpperCase() == "TBODY")) { if (!this.tBodies[0]) { return; } else { tb = this.tBodies[0]; } } //添加一个隐藏行,后面新增行复制此行 var lastRow = tb.rows[tb.rows.length - 1]; var row = $(lastRow).clone(true, true); $(row).insertAfter($(tb).find("tr:last")).hide(); //为除所有行添加事件,当获得焦点时自动增加新行 for (var i = 0; i < tb.rows.length; i++) { AddAutoRowsEvent(tb.rows[i]); } }); } }); //自动增加行 function autoRows(e) { var e = e || event; var obj = e.target || e.srcElement; while (obj.tagName != "TR") { obj = obj.parentNode; } var tb = obj.parentNode; var index = $(obj).index(); var n = 5 - (tb.rows.length - index); if (n > 0) { var lastRow = tb.rows[tb.rows.length - 1]; for (var j = 0; j < n; j++) { var row = $(lastRow).clone(true, true); //将新行添加到最后一行之前 row.insertBefore($(tb).find("tr:last")).show(); //为新增加的行添加事件 //AddAutoRowsEvent(tb.rows[tb.rows.length - 2]); //如果有回调函数则执行 if (typeof (rowfunction) == 'function') { rowfunction(row); } } } } //为指定行增加事件 function AddAutoRowsEvent(tr) { //如果是JQuery对象则转为HTML对象 if (tr instanceof jQuery) { tr = tr[0]; } $(tr).bind('click', autoRows); var c = tr.cells.length; for (var j = 0; j < c; j++) { var childs = tr.cells[j].childNodes; for (var k = 0; k < childs.length; k++) { if (childs[k].type == "text" || childs[k].type == "textarea" || childs[k].type == "button") { $(childs[k]).bind('focus', autoRows); } } } } //在表格中指定位置插入指定行数,新插入的行内容为同一表格主体最后一行 //obj:行内的任意对象 //n:要增加的行数 //bAutoRows:是否要添加自动增加行的属性 $.fn.tableAutoRow.insertRow = function (obj, n, bAutoRows, isInsertAfter) { var loop = 0; //加入循环次数,防止死循环 while (obj.tagName != "TR" && loop < 10) { obj = obj.parentNode; loop++; } if (obj.tagName != "TR") { return; } var tb = obj.parentNode; switch (arguments.length) { case 3: var isInsertAfter = true; case 2: var bAutoRows = true; var isInsertAfter = true; case 1: var bAutoRows = true; var isInsertAfter = true; var n = 1; } for (var i = 0; i < n; i++) { var lastRow = tb.rows[tb.rows.length - 1]; var row = $(lastRow).clone(true, true); //将新行添加到当前行之前/后 if (isInsertAfter) { row.insertAfter(obj).show(); } else { row.insertBefore(obj).show(); } if (bAutoRows) { AddAutoRowsEvent(row); } } } //清除指定行数据 //obj为行或者行内的节点 //startColnum:起始列 //endColumn:终止列 //isReset:是否恢复到初始值 $.fn.tableAutoRow.clearRowData = function (obj, startColnum, endColumn, isReset) { var loop = 0; //加入循环次数,防止死循环 while (obj.tagName != "TR" && loop < 10) { obj = obj.parentNode; loop++; } if (obj.tagName != "TR") { return; } var cellsCount = obj.cells.length; //此行单元格总数 if (startColnum < 0 || !startColnum) { //如果未指定清除起始列则从第一列清除 startColnum = 0; } if (endColumn > cellsCount - 1 || !endColumn) { //如果未指定清除终止列则清除到最后一列前(通常最后一列用于放置清除按钮) endColumn = cellsCount - 1; } if (isReset == undefined) { isReset = false; } for (var c = startColnum; c <= endColumn; c++) //循环各列,设置单元格里的控件值 { for (var j = 0; j < obj.cells[c].childNodes.length; j++) { //循环处理指定单元格中的子节点 var node = obj.cells[c].childNodes[j]; setObjData(node, isReset); } } }; function setObjData(node, isReset) { switch (node.type) { case "text": case "hidden": case "textarea": if (isReset) { node.value = node.defaultValue; } else { node.value = ""; } break; case "select-one": case "select-multiple": if (isReset) { for (var k = node.options.length - 1; k >= 0; k--) { node.options[k].selected = node.options[k].defaultSelected; } } else { for (var k = node.options.length - 1; k >= 0; k--) { //node.options.remove(k); node.options[k].selected = false; } } break; case "checkbox": case "radio": if (isReset) { node.checked = node.defaultChecked; } else { node.checked = false; } break; } if (node.childNodes && node.childNodes.length > 0) { var l = node.childNodes.length; for (var i = 0; i < l; i++) { setObjData(node.childNodes[i], isReset); } } } })(jQuery);

JavaScriptの最新トレンドには、TypeScriptの台頭、最新のフレームワークとライブラリの人気、WebAssemblyの適用が含まれます。将来の見通しは、より強力なタイプシステム、サーバー側のJavaScriptの開発、人工知能と機械学習の拡大、およびIoTおよびEDGEコンピューティングの可能性をカバーしています。

JavaScriptは現代のWeb開発の基礎であり、その主な機能には、イベント駆動型のプログラミング、動的コンテンツ生成、非同期プログラミングが含まれます。 1)イベント駆動型プログラミングにより、Webページはユーザー操作に応じて動的に変更できます。 2)動的コンテンツ生成により、条件に応じてページコンテンツを調整できます。 3)非同期プログラミングにより、ユーザーインターフェイスがブロックされないようにします。 JavaScriptは、Webインタラクション、シングルページアプリケーション、サーバー側の開発で広く使用されており、ユーザーエクスペリエンスとクロスプラットフォーム開発の柔軟性を大幅に改善しています。

Pythonはデータサイエンスや機械学習により適していますが、JavaScriptはフロントエンドとフルスタックの開発により適しています。 1. Pythonは、簡潔な構文とリッチライブラリエコシステムで知られており、データ分析とWeb開発に適しています。 2。JavaScriptは、フロントエンド開発の中核です。 node.jsはサーバー側のプログラミングをサポートしており、フルスタック開発に適しています。

JavaScriptは、最新のブラウザにすでに組み込まれているため、インストールを必要としません。開始するには、テキストエディターとブラウザのみが必要です。 1)ブラウザ環境では、タグを介してHTMLファイルを埋め込んで実行します。 2)node.js環境では、node.jsをダウンロードしてインストールした後、コマンドラインを介してJavaScriptファイルを実行します。

Quartzタイマーを使用してタスクをスケジュールする場合、Quartzでタスク通知を事前に送信する方法、タスクの実行時間はCron式によって設定されます。今...

JavaScriptプログラミング、プロトタイプチェーンの関数パラメーターの理解と操作のJavaScriptのプロトタイプチェーンの関数のパラメーターを取得する方法は、一般的で重要なタスクです...

WeChatアプレットWeb-ViewでVue.jsを使用する動的スタイルの変位障害がvue.jsを使用している理由の分析...

複数のリンクの同時ゲットリクエストを作成し、結果を返すために順番に判断する方法は? TamperMonkeyスクリプトでは、複数のチェーンを使用する必要があることがよくあります...


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

WebStorm Mac版
便利なJavaScript開発ツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

ホットトピック



