我試圖找出如何讓我的HTML嵌套項目的價值得到了嵌套項的值。 我的HTML結構如下jQuery的通過
<DIV class=s4-ql id=zz17_V4QuickLaunchMenu>
<DIV class="menu vertical menu-vertical">
<UL class="root static">
<LI class=static><A title="Executive Team description updated" class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Executive Team</SPAN> </SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background> <SPAN class=menu-item-text>Finance</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background> <SPAN class=menu-item-text>Human Resources</SPAN></SPAN></A></LI>
<LI class="static selected">
<A class="static selected menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Information Technology</SPAN><SPAN class=ms-hidden>Currently selected</SPAN></SPAN></A>
<UL class=static>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Calendar</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Contacts</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background> <SPAN class=menu-item-text>Discussions</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Shared Documents</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Workspaces</SPAN></SPAN></A></LI>
</UL></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Legal</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Manufacturing</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Sales</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Purchasing</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Safety</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional-background><SPAN class=menu-item-text>Sales/Materials</SPAN></SPAN></A></LI>
<LI class=static><A class="static menu-item" href="#"><SPAN class=additional- background><SPAN class=menu-item-text>Traffic</SPAN></SPAN></A></LI>
</UL>
</DIV>
</DIV>
任何時候我用下面的jQuery
var siteTitle = $(".s4-ql").find(".menu-item-text").text();
我能夠獲得UL中的第一個項目,但我似乎無法過濾我的結果讓我可以針對S4-SQL類,然後靜態項目中選擇,然後選擇菜單項文本,我需要得到的。我嘗試過使用多個類來定位特定項目的各種變體,但沒有運氣。
var siteTitle = $(".s4-ql.static selected menu-item").find(".menu-item-text").text();
var siteTitle = $(".s4-ql .static selected menu-item").find(".menu-item-text").text();
var siteTitle = $(".static selected menu-item").find(".menu-item-text").text();
var siteTitle = $(".s4-ql .static selected menu-item .menu-item-text").text();
沒有上述方法工作,這似乎很簡單,但我沒有得到它!
你的HTML是無效的 - 只有'麗'元素可以是'ul'的直接子元素。你的'span'元素將出現在'ul'之外。 –
我更新使用我的實際HTML的sniplet,很着急,並認爲這將是更快地傳達的理念。 – digitalslavery