jquery的closest方法和parents方法的区别
该方法从元素本身开始往上查找,返回最近的匹配的祖先元素。
1、closest查找开始于自身,parents开始于元素父级
2、closest向上查找,知道找到一个匹配就停止查找,parents一直查找到根元素,并将匹配的元素加入集合
3、closest返回的是包含零个或一个元素的jquery对象,parents返回的是包含零个或一个或多个元素的jquery对象
function valuation(obj){ var other = $(obj).val(); if(other!="" && other!="其他"){ $(obj).parent().closest("td").find("input[name='brand_name[qitas][]']").val(other); $(obj).parent().closest("td").find("input[name='brand_name[qita][]']").val(other); $(obj).parent().closest("td").find("input[name='brand_name[qitas][]']").attr("checked","checked"); }else{ $(obj).parent().closest("td").find("input[name='brand_name[qitas][]']").removeAttr("checked"); } }
$(obj).closest("div.card-list").html(); 往上匹配最近的一个DOM