我有一个包含一系列输入字段的表单,我也用这个表单动态地添加了javascript输入字段。我想用下面的代码删除这些元素动态以及:从具有值的窗体中移除输入元素导致网站崩溃
var catchMarkers = [];
var fishingtripMarker;
var catchIdCounter = 0;
function placeCatchMarker(position)
{
catchMarker = new google.maps.Marker({
position: position,
map: map,
draggable: true,
animation: google.maps.Animation.DROP
});
catchMarker.set("id", catchIdCounter);
AddCatchInput(catchIdCounter);
catchIdCounter++;
//Right click listener
markerListener = google.maps.event.addListener(catchMarker, 'rightclick', function(event) {
//removing inputs from form
var fish = document.getElementById('Fish'+this.get("id"));
var weight = document.getElementById('Weight'+this.get("id"));
fish.parentNode.removeChild(fish);
weight.parentNode.removeChild(weight);
//removing marker
this.setMap(null);
var index = catchMarkers.indexOf(this);
catchMarkers.splice(index, 1);
});
catchMarkers.push(catchMarker);
}
我创建这些inputfields与此代码:
function AddCatchInput($id)
{
var container = document.getElementById("myform");
var select = document.createElement("select");
select.setAttribute("id", "Fish"+$id);
var option;
option = document.createElement("option");
option.setAttribute("value", "1");
option.innerHTML = "Trout";
select.appendChild(option);
var input = document.createElement("input");
input.id = "Weight" + $id;
container.appendChild(select);
container.appendChild(input);
}
一切工作正常,直到我尝试删除这些输入字段,当任何形式inputfields有值,然后站点崩溃,我不知道为什么。
更好地检查浏览器控制台是否有任何错误。 – Praveen
请定义'崩溃' – jkw4703
你能发布一个完整的代码示例,允许我们重现此问题吗?并尽可能以jsFiddle.net为例。 – j08691