我請求創(chuàng)建一個表,當(dāng)在一行的最后一列上按 TAB 時添加“動態(tài)”行。最終我用 HTML 創(chuàng)建了一個結(jié)構(gòu)<table id="some_table"><tr> <td> <input type="text" /> </td> <td> <input type="text" /> </td> <td> <input type="text" /> </td></tr>然后我在 JS 中使用了這個簡單的代碼$('#some_table').on('keydown', 'input', function (e) { var keyCode = e.keyCode; if (keyCode !== 9) return; var $this = $(this), $lastTr = $('tr:last', $('#some_table')), $lastTd = $('td:last', $lastTr); if (($(e.target).closest('td')).is($lastTd)) { $lastTr.after($lastTr.clone()); }});我已經(jīng)添加了腳本源<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>它實際上做了什么,當(dāng)您鍵入數(shù)據(jù)并在最后一個上按 TAB 時,clone() 正在克隆帶有數(shù)據(jù)的最后一行,我想避免這種情況。我只想克隆新行的空列,事實上,創(chuàng)建具有相同結(jié)構(gòu)但沒有任何數(shù)據(jù)的新行。怎樣才能做到這一點呢?我已經(jīng)添加了jsfiddle鏈接
在 jquery 中使用 .clone() 時如何停止克隆在 <Td> 元素內(nèi)輸入的文本
莫回?zé)o
2023-09-28 15:51:35