我有以下的HTML文件:删除创建复选框使用jQuery
<div class="tituloD">
</div>
<div class="subtituloD">
</div>
<div class="puntosD">
</div>
我有这个jQuery的javascript:
// Esta funcion recoge el json data de puntos importantes y lo imprime en pantalla
function resultsPuntos(data) {
//Si el punto no se ha creado antes, se crea la estructura
if(puntosCreados == "No"){
$("div.puntosD").append("Puntos importantes: ");
$.each(data,function(index,value) {
$("div.puntosD").append('<input type=\"checkbox\" name="'+data[index].id+'" value="'+data[index].nombre+'"> '+data[index].nombre);
});
puntosCreados = "Si";
}
else{
//Vaciar estructura
$("#checkbox").replaceWith('');
//Crear estructura de nuevo
$.each(data,function(index,value) {
$("div.puntosD").append('<input type=\"checkbox\" name="'+data[index].id+'" value="'+data[index].nombre+'"> '+data[index].nombre);
});
}
}
我想显示从数据库正在添加的选项复选框。为此,我检测它是否是第一次创建它(if(puntosCreados == "No")
),如果是这样,我编写复选框结构。如果不是,我尝试先清空复选框结构($("#checkbox").replaceWith('');
),但是,这不起作用。我该怎么做?
你有一个id =“checkbox”的元素吗?我没看到它。 – Jere