Javascript 如何从div级别删除动态生成的字段?
我的概念是在点击“添加”按钮时创建最多20个块(它包含一些输入字段),如果点击“添加”按钮,则可以添加新块,这是成功的。现在我想删除在“添加”按钮点击时创建的块 例如:如果用户正在使用“添加”按钮创建5个块。如果用户点击块2中的“减号”按钮,则块2应从列表中删除,块的计数应相应更新。Javascript 如何从div级别删除动态生成的字段?,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,我的概念是在点击“添加”按钮时创建最多20个块(它包含一些输入字段),如果点击“添加”按钮,则可以添加新块,这是成功的。现在我想删除在“添加”按钮点击时创建的块 例如:如果用户正在使用“添加”按钮创建5个块。如果用户点击块2中的“减号”按钮,则块2应从列表中删除,块的计数应相应更新。 var i=1; $(文档).ready(函数(){ $(“#commentForm”).validate(); }); 函数add() { var objTo=document.getElementBy
var i=1;
$(文档).ready(函数(){
$(“#commentForm”).validate();
});
函数add()
{
var objTo=document.getElementById('room\u fileds')
var divtest=document.createElement(“div”);
var label=document.createElement('label');
label.innerHTML='Block'+i+'';
divtest.appendChild(标签);
var length=$('#length').clone().attr('id','length'+i).attr('name','length'+i);
var attribute=$('#attribute').clone().attr('id','attribute'+i).attr('name','attribute'+i);
var column=$('#column').clone().attr('id','column'+i).attr('name','column'+i);
长度。附录(divtest);
attribute.appendTo(divtest);
列。附录(divtest);
目标追加儿童(divtest);
我++
}
函数负()
{
}
静电场
字段列
对
不
单击即可删除标签父项。请参见减号函数内容
var i=1;
$(文档).ready(函数(){
$(“#commentForm”).validate();
});
函数add()
{
var objTo=document.getElementById('room\u fileds')
var divtest=document.createElement(“div”);
var label=document.createElement('label');
label.innerHTML='Block'+i+'';
divtest.appendChild(标签);
var length=$('#length').clone().attr('id','length'+i).attr('name','length'+i);
var attribute=$('#attribute').clone().attr('id','attribute'+i).attr('name','attribute'+i);
var column=$('#column').clone().attr('id','column'+i).attr('name','column'+i);
长度。附录(divtest);
attribute.appendTo(divtest);
列。附录(divtest);
目标追加儿童(divtest);
我++
}
函数负()
{
//这是单击的标签,因此我们删除父项(div)
$(this.parent().remove();
}
静电场
字段列
对
不
-
var包装器=$(“.formgroup”);
$(“#添加按钮”)。单击(功能(e){
e、 预防默认值();
$(“#phoneNumberList”).append(“”;
});
$(.removePhoneDiv”)。在(“单击”,“删除电话号码”功能上(e){
e、 预防默认值();
$(this.parent('div').parent('li').remove();
})
在创建div
节点时设置id
divtest.setAttribute("id", "div" + i);
对于减号函数
在onclick
label.innerHTML = '<h5 class="label">Block '+i+'<input type="button" onclick="minus('+i+')" value="Minus"></h5>';
var i=1;
$(文档).ready(函数(){
//$(“#commentForm”).validate();
});
函数add()
{
var objTo=document.getElementById('room\u fileds')
var divtest=document.createElement(“div”);
setAttribute(“id”、“div”+i);
var label=document.createElement('label');
label.innerHTML='Block'+i+'';
divtest.appendChild(标签);
var length=$('#length').clone().attr('id','length'+i).attr('name','length'+i);
var attribute=$('#attribute').clone().attr('id','attribute'+i).attr('name','attribute'+i);
var column=$('#column').clone().attr('id','column'+i).attr('name','column'+i);
长度。附录(divtest);
attribute.appendTo(divtest);
列。附录(divtest);
目标追加儿童(divtest);
我++
}
函数负(_id)
{
var\u div\u id=“div”+\u id;
var\u div\u elem=document.getElementById(\u div\u id);
_div_elem.parentNode.removeChild(_div_elem);
}
静电场
字段列
对
不
为什么php tagget会出现在这里?
divtest.setAttribute("id", "div" + i);
label.innerHTML = '<h5 class="label">Block '+i+'<input type="button" onclick="minus('+i+')" value="Minus"></h5>';
function minus(_id)
{
var _div_id = "div" + _id;
var _div_elem = document.getElementById(_div_id);
_div_elem.parentNode.removeChild(_div_elem);
}