当我有父 JQuery/JS 的类名称时,如何从子 ID 获取 ID 父级

How to get ID Parent from Child ID when i have className of the Parents JQuery/JS

本文关键字:ID 父级 获取 JQuery JS      更新时间:2023-09-26

首先,对不起,我的英语说得不太好,

我想通过使用其子 p:inputText 的 id 和 p:dialog 客户端的 class="ui-dialog-title" 来获取 Javascript 中 p:dialog 的 ID。

<h:form id="formID" >
<p:dialog id="DialogID"  header="Title"  widgetVar="v_DialogID">
        <p:inputText   id="InputID"  value="#{bean.input}"  onblur="changeTitle(this.id)" />
</p:dialog>
</h:form>

我想这就是你要问的。如果我错了,请纠正我。

$("#InputID").parent().attr("id"); 将获取元素直系父级的 ID。

$("#InputID").parents() 会让你所有的父母都为一个元素。

$("#InputID").parents(".class").each(function () { console.log($(this).attr("id")); }); 将为您提供具有给定元素类的每个父级的 ID。