未捕获的类型错误:无法读取属性'删除'的未定义

Uncaught TypeError: Cannot read property 'remove' of undefined

本文关键字:属性 未定义 删除 读取 类型 错误      更新时间:2023-09-26

未工作&不删除弹出窗口(_up)

function add_comm(){
if($("#fio").val().length>0&&$("#ms_comment").val().length>0){
    $.post('/send.php',{subject:"Комент",message:"FIO: "+$("#fio").val()+"<br /> Comment: "+$("#ms_comment").val()+"<br>"});
    $(".bs-example-modal-sm").modal("show");
    $('.bs-example-modal-sm .modal-content')[0].remove();
    $("#ffrr").html('We call U');
}else{
    alert('Warning');
}
}

HTML

<button type="button" class="btn btn-default" onclick="add_comm(); return true;">Send</button>

要只删除第一个元素,请使用jQuery选择器:

$('.bs-example-modal-sm .modal-content:first').remove();

但是,如果您使用引导模式,也许您还应该查看模式切换函数。

执行[0]时,它将获取DOM元素本身。DOM元素没有remove()方法。您需要jQuery值。因此:

$('.bs-example-modal-sm .modal-content').remove();

请参阅此JSFiddle:http://jsfiddle.net/skipallmighty/186ztcbh/