jquery遍历之parent()和parents()的区别及parentsUntil()方法详解

2020-05-17 06:19:18易采站长站整理

    var str=”;
    $(“.tab input[name=checkbox]:checked”).each(function(){
        str+=$(this).val()+’,’;
    });
    str=str.substring(0,str.length-1);
    if(chk_Batch_PKEY(str)){
        art.dialog.confirm(‘你确认删除选中的日志吗?’,function(){
            $.post(“myRun/managerlog_del.php”,{id:str},function(tips){
                if(tips==’ok’){
                    art.dialog.through({title:’信息’,icon:’face-smile’,content:’删除成功’,ok:function(){art.dialog.close();location.reload();}});
                }else{
                    art.dialog.tips(‘删除失败’);
                }
            });
            return true;
        });
    }else{
        art.dialog.through({title:’信息’,icon:’face-sad’,content:’请选择删除的日志’,ok:function(){art.dialog.close();}});
    }
}).addClass(“pointer”);



//del event
$(“.del”).bind(“click”,function(event){
    var _tmpQuery=$(this);
    var id=$(“input[name=’id’]”,$(this).parents(“form:first”)).attr(“value”);
    art.dialog.confirm(‘你确认删除该日志吗?’,function(){
        $.post(“myRun/managerlog_del.php”,{id:id},function(tips){
            if(tips==’ok’){
                art.dialog.tips(‘成功删除’);
                _tmpQuery.parents(‘tr:first’).hide();
            }else{
                art.dialog.tips(tips,5);
            }
        });
        return true;
    });
});

涉及到的知识点:


var id=$(“input[name=’id’]”,$(this).parents(“form:first”)).attr(“value”);


参考文献:
parent():http://www.w3school.com.cn/jquery/traversing_parent.asp


parents():http://www.w3school.com.cn/jquery/traversing_parents.asp



parentsUntil() 方法


定义:parentsUntil() 获得当前匹配元素集合中每个元素的祖先元素,直到(但不包括)被选择器、DOM 节点或 jQuery 对象匹配的元素。