如何使用javascript在DIV中删除文本框。首先,我在div中创建了四列,并使用div中的Add按钮动态创建了复选框。如何使用javascript在DIV中动态删除文本框
我的问题是我需要使用删除按钮(在文本框后面)删除相应的文本框。
所以请给我一个解决方案来纠正它。
function Add() {
div1.innerHTML += "<br><br> <input type='text' name='mytext'>" + "<input type='button' value='Delete' onclick='removeRow(this)'>";
div2.innerHTML += "<br><br> <input type='text' name='mytext'>" + "<input type='button' value='Delete' onclick='removeRow(this)'>";
div3.innerHTML += "<br><br> <input type='text' name='mytext'>" + "<input type='button' value='Delete' onclick='removeRow(this)'>";
div4.innerHTML += "<br><br> <input type='text' name='mytext'>" + "<input type='button' value='Delete' onclick='removeRow(this)'>";
}
function removeRow(input) {
document.getElementById('div1').removeChild(input.parentNode);
}
#Wrapper {
width: 90%;
margin: 0 auto;
}
#div1 {
float: left;
width: 20%;
background: lightblue;
}
#div2 {
float: left;
width: 20%;
background: lightyellow;
}
#div3 {
float: left;
width: 20%;
background: lightgray;
}
#div4 {
float: left;
width: 20%;
background: lightblue;
}
#ClearFix {
clear: both;
}
<button onclick="Add()">Add TextBox</button>
<div id="Wrapper">
<div id="div1">
<p>This is Div one</p>
</div>
<div id="div2">
<p>This is Div two</p>
</div>
<div id="div3">
<p>This is Div threee</p>
</div>
<div id="div4">
<p>This is Div Four</p>
</div>
<div id="ClearFix"></div>
</div>
你拨弄https://jsfiddle.net/u7gdatgj/ – 3rdthemagical
它不PLZ工作给我一个解决方案 –
您在添加有未解决的变量()FUNC:DIV1,DIV2。 .. – 3rdthemagical