我有一个文本区域,旁边有两个按钮:“添加另一个文本区域”和“删除这个文本区域”
这是我的html代码:
<div id="summaryIn">
<label for="">Summary of Experience:</label>
<textarea class="TA1" name="mySummary[]" value=""></textarea>
<button class="adddel" name="cmdDelSummary[]" id="cmdDelSummary" title="Delete this Summary" onClick="DelSummary('summaryIn');">-</button>
<button class="adddel" id="cmdAddSummary" title="Add Another Summary" onClick="AddSummary('summaryIn');">+</button>
</div>
我用于添加 textarea 的 javascript 函数工作正常,但是删除按钮不能正常工作,这是 javascript 代码:
function DelSummary(divName){
alert(summary_counter);
if (summary_counter == 1)
{
document.getElementById('cmdDelSummary').disabled=true;
}
else
{
summaryIn.removeChild(summaryIn.lastChild);
summary_counter--;
//alert(summary_counter);
}
}
我一直在尝试解决这个问题很长时间,但直到现在我还没有找到任何解决方案。. .我不知道如何索引/引用其他删除按钮,以便 removeChild 仅删除该特定文本区域,而不总是删除 lastChild ..非常感谢提前:)