在jquery中使用.next css选择器,其中有多个元素

时间:2016-04-05 09:05:36

标签: jquery html css

我有一个“Typedematériel”的值 COL 中有一个css选择器,这是我的代码:

<th nowrap scope="col" onmouseover="OnChildColumn(this)" class="ms-vh2">
    <div Sortable="" SortDisable="" FilterDisable="" Filterable="" FilterDisableMessage="" name="LinkTitle" CTXNum="123" DisplayName="Type de matériel" FieldType="Computed" ResultType="" SortFields="View={69d1eb84-0c41-4f10-93d3-4a0c2e62a646}&SortField=LinkTitle&amp;SortDir=Asc" class="ms-vh-div">
        <a id="diidSortLinkTitle" onfocus="OnFocusFilter(this)" href="javascript: " onclick="javascript:return OnClickFilter(this,event);" SortingFields="View={69d1eb84-0c41-4f10-93d3-4a0c2e62a646}&SortField=LinkTitle&amp;SortDir=Asc">
            Type de matériel
            <img src="/_layouts/images/blank.gif" class="ms-hidden" border="0" width="1" height="1" alt="Appuyez sur Maj+Entrée pour ouvrir le menu (nouvelle fenêtre)." />
        </a><img src="/_layouts/images/blank.gif" alt="" border="0" /><img src="/_layouts/images/blank.gif" border="0" alt="" />
    </div>

    <div class="s4-ctx">
        <span> 
        </span>
        <a onfocus="OnChildColumn(this.parentNode.parentNode); return false;" onclick="PopMenuFromChevron(event); return false;" href="javascript:;" title="Menu Ouvrir">
        </a>
        <span> 
        </span>
    </div>
</th>

<th nowrap scope="col" onmouseover="OnChildColumn(this)" class="ms-vh2">
    <div Sortable="" SortDisable="" FilterDisable="" Filterable="" FilterDisableMessage="" name="Provenance" CTXNum="123" DisplayName="Provenance" FieldType="Text" ResultType="" SortFields="View={69d1eb84-0c41-4f10-93d3-4a0c2e62a646}&SortField=Provenance&amp;SortDir=Asc" class="ms-vh-div">
        <a id="diidSortProvenance" onfocus="OnFocusFilter(this)" href="javascript: " onclick="javascript:return OnClickFilter(this,event);" SortingFields="View={69d1eb84-0c41-4f10-93d3-4a0c2e62a646}&SortField=Provenance&amp;SortDir=Asc">
            Provenance
            <img src="/_layouts/images/blank.gif" class="ms-hidden" border="0" width="1" height="1" alt="Appuyez sur Maj+Entrée pour ouvrir le menu (nouvelle fenêtre)." />
        </a>
        <img src="/_layouts/images/blank.gif" alt="" border="0" />
        <img src="/_layouts/images/blank.gif" border="0" alt="" /></div>

就像那样:

var elem_title="th.ms-vh2 div a#diidSortLinkTitle";
var COL=$(elem_title).text();

我得到COL = "Type de matériel"

我想要COL =“Provenance”,基于我之前给你的COL值。

我尝试使用.next,或者尝试在.next之后执行.text:

var COL="th.ms-vh2 div a#diidSortLinkTitle";
COL=$(COL).next().text();

但它没有用,.text()什么也没给我。

你能帮我做这个吗?下一个?

1 个答案:

答案 0 :(得分:1)

试试这个

$("th.ms-vh2:eq(0) div a").text();       //First value
$("th.ms-vh2:eq(1) div a").text();       //Second value