简体   繁体   English

克隆后如何清除输入,选择和文本区域字段

[英]How do i clear input,select and textarea fields after cloning

i'm create form for expose item i want fresh text field. 我正在为需要新文本字段的暴露项目创建表单。 when user click button ADD 当用户单击按钮添加时

 function fncAdd() { //ADD ROW AND CLONE var tb = document.getElementById('tbl'); var tbody = document.createElement('tbody'); // fixed IE :> tb.insertBefore(tbody, null); var clone = document.getElementById('cln').cloneNode(true); tbody.insertBefore(clone, null); } function fncDelete() { //DELETE ROW var tb = document.getElementById('tbl'); var del = tb.rows.length; if (del > 1) { tb.deleteRow(del - 1); } } 
 <tr id="cln"> //CALL CLONE FUNCTION <div align="center">1</div> </td> <?php //CONNECT DATABASE include 'dbConfig.php'; $query = $db->query("SELECT * FROM accountcode ORDER BY acc_id ASC "); $rowCount = $query->num_rows; ?> <td> <select id="accountcode"> //DROPDOWN 2ND BY AJAX <option value=""> - - Please select - - </option> <?php if($rowCount > 0){ while($row=$query->fetch_assoc()){ echo '<option value="'.$row['acc_id'].'">'.$row['acc_name'].'</option>'; } }else{ echo '<option value="">Accountcode not available</option>'; } ?> </select> </td> <td> <select id="item"> //DROPDOWN 2ND BY AJAX <option value=""> - - Select accountcode first - -</option> </select> </td> <td> //DETAIL BOX <textarea rows=4 cols=25 class="txtDETAIL" maxlength="100"> </textarea> </td> <td> <input type="text" class="txtAMOUNT" size="5"> //AMOUNT BOX </td> <td> <input type="text" class="txtUNIT" size="5"> //UNIT BOX </td> <td> //NOTE BOX <textarea rows=4 cols=15 class="note" maxlength="60"> </textarea> </td> <td> //UPLOADFILE FOR PICTURE OR STOCK <a href='upload.php?id={$row[' id="id" ']}'>CLICK</a> </td> </table> <p> <input type="button" value="ADD" onClick="fncAdd()"> //BUTTON ADD <input type="button" value="DELETE" onClick="fncDelete()"> //BUTTON DELETE </p> 

I am having trouble to create text field value when user click button i want to clone function not copy old value from 1st row and column NO can auto increment 当用户单击按钮时,我想创建文本字段值时遇到麻烦,我想克隆功能不从第一行和第一列复制旧值,NO可以自动递增

how can i do that 我怎样才能做到这一点

EXAMPLE

To clear form data you can use, 要清除您可以使用的表单数据,

document.getElementById("form1").reset();

Your form should look like, 您的表格应如下所示:

<form id="form1">
   <input .....
</form>

Something to be aware of, is the cloned element has unique ID's (eg, append -1 etc onto the original ID). 需要注意的是,克隆的元素具有唯一的ID(例如,在原始ID上附加-1等)。

Also, I've recently done this using jQuery, however, I used string.replace(regex, ''); 另外,我最近使用jQuery完成了此操作,但是我使用了string.replace(regex,'');。 instead of this method. 而不是这种方法。

Oh yeah, an example to edit to suit your situation: 哦,是的,可以根据您的情况进行编辑的示例:

var element = document.getElementById('id-of-element').cloneNode(true);

element.childNodes[x].nextSibling.childNodes[y].value = '';

document.getElementById('target-element').insertBefore(element, null);

Kind regards, 亲切的问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM