Dir.pwd + "/../"
指定路径+"/../" 这样就能得到上级目录
你想要的直接方法没有,这个我已经找过了!
应为我也有和你一样的应用!
jquery中parent()可以获取父级元素,所以获得某元素父级的父级可以使用
$(selector).parent().parent()示例如下
创建Html代码及css样式
<div class="class1">class1
<div class="class2">
class2
<div class="class3">
class3
</div>
</div>
</div> div{padding:10px 20pxborder:4px solid #ebcbbe}
div.class1{width:200pxheight:120px}
编写jquery代码
$(function(){$("div.class3").click(function() {
obj = $(this).parent().parent()
alert(obj.prop('class'))
})
})
查看效果
parent()是 父元素 就一个,你要选取class=x的元素,就是第一个p元素的父元素的父元素:$("p:eq(0)").parent().parent().css("background", "yellow")
或者p元素父元素的父元素类为x的元素:
$("p").parent().parent(".x").css("background", "yellow")
或者p元素祖先元素(祖先就很多个了)中类为x的元素:
$("p").parents(".x").css("background", "yellow")