如何使用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