Javascript 需要复制代码吗
伙计们,我有一个输出文本框的代码,信息将被保存Javascript 需要复制代码吗,javascript,html,Javascript,Html,伙计们,我有一个输出文本框的代码,信息将被保存 <tbody id="1111111"> <tr> <td class="ObjektiivneLeid">The function</td> <td class="Hinnang"> <input class="Hinnang_Valimata" type="radio" name="1111111_Hinnang" value="Valimata"
<tbody id="1111111">
<tr>
<td class="ObjektiivneLeid">The function</td>
<td class="Hinnang">
<input class="Hinnang_Valimata" type="radio" name="1111111_Hinnang" value="Valimata" id="1111111_Hinnang_Valimata" />Valimata
<input class="Hinnang_norm" type="radio" name="1111111_Hinnang" id="364644000_Hinnang_NORM" value="NORM" />NORM
<input class="Hinnang_pat checkbox_idParent" type="radio" name="1111111_Hinnang" id="1111111_Hinnang_Patoloogia" value="Patoloogia"/>Leid</td>
<td class="Patoloogia">kuupäev
<input id="1111111_otherInfo_kuupaev" name="1111111_otherInfo_kuupaev" type="text" value="" class="Patoloogia_text" onFocus="gnlGotFocus(getCurrentDate(),this);"
onKeyDown="javascript:gnlKeyDown('00.00.0000',this,event);" maxlength='10'
onblur="javascript:gnlDateValid(this,event,false);"/></td>
</tr>
<tr>
<td class="title_sub Patoloogia">sight</td>
<td class="Patoloogia"><input id="1111111_otherInfo_sight" name="1111111_otherInfo_sight" type="text" value="" class="Patoloogia_text"></td>
</tr>
<tr>
<td class="title_sub Patoloogia">hearing</td>
<td class="Patoloogia"><input id="364644000_otherInfo_hearing" name="364644000_otherInfo_hearing" type="text" value="" class="Patoloogia_text"></td>
<td class="title_sub Patoloogia">speech</td>
<td class="Patoloogia"><input id="1111111_otherInfo_speech" name="1111111_otherInfo_speech" type="text" value="" class="Patoloogia_text"></td>
</tr>
<tr>
<td class="title_sub Patoloogia">mobility</td>
<td class="Patoloogia"><input id="1111111_otherInfo_mobility" name="1111111_otherInfo_mobility" type="text" value="" class="Patoloogia_text"></td>
<td class="title_sub Patoloogia">movement</td>
<td class="Patoloogia"><input id="1111111_otherInfo_movement" name="1111111_otherInfo_movement" type="text" value="" class="Patoloogia_text"></td>
</tr>`
功能
缬草
标准
莱德
库帕耶夫
景象
听力
演讲
流动性
移动
`
这是一段代码,它给了我要填写的框,我需要为代码创建一个添加系统,所以当我按下I.e.“+”时,它会复制代码,我有新的字段要填写和保存。此外,如果需要,我需要和“x”按钮来删除新字段。有什么建议我该怎么做(我希望我的解释不会让人困惑)
我需要类似于
的东西,但我不知道在onClick中添加什么…我知道这看起来很愚蠢,但我确实需要一些帮助在包含文本框的父对象上使用appendChild(n)和removeChild(n)。如果我理解正确,您将需要JQuery。在找这样的东西吗
$(document).ready(function() {
var dupe = $('#parent_0').clone();
var id = 1;
$(document).on('click', '#plus', function() {
id++;
var newForm = $(dupe).clone().attr('id', 'parent_'+id);
$('body').append(newForm);
});
$(document).on('click', '#delete', function() {
id--;
$('[id^="parent_"]:last').remove();
});
});
我已经做了一个基于你的代码,让你看看
出于演示目的,使用了div。代码周围应该有一个form标记,因为它实际上是一个表单,但JSFIDLE似乎不喜欢在其应用程序中使用表单。单击按钮#plus时,此div元素将使用.clone()进行克隆,并使用.attr()获得唯一属性
#delete删除文档中id以parent#开头的最后一个克隆元素
发布内容时,请确保将整个内容粘贴到问题中。主题之外,但一般来说,使用数字ID是个坏主意。例如
id=“1111111”
。如果您使用那样的id,您可能会遇到一些浏览器兼容性问题。实际上我没有该值,将其更改为id=“1111111”我还有其他语言的标题。这是右边的。我不小心给你送错了小提琴。可惜你的问题被否决了。如果Stack Exchange的监管用户真的会帮忙,而不是否决一个简单的问题,那么像你和我这样的程序员会更有动力。因此,我将所有HTML代码添加到JSFIDLE中,但它并不像我需要它那样工作(我注释掉了需要复制的部分)因此,如果您有任何想法如何解决当前的问题,那么最好是与代码的链接。在小提琴中看不到您已注释掉的内容。您希望复制哪个部分?抱歉,这应该是正确的链接,注释部分位于endor add jsfiddle.net/AK9CC/22,而不是jsfiddle.net/AK9CC/21,同一代码有一个不同的版本需要复制