我有一个 “Type de maté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&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&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&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&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 值,我想要 COL = "Provenance"。
我尝试使用 .next,或者尝试在 .next 之后使用 .text:
var COL="th.ms-vh2 div a#diidSortLinkTitle";
COL=$(COL).next().text();
但它不起作用,.text() 什么也没给我。
你能帮我做这个 .next 的工作吗?
最佳答案
试试这个
$("th.ms-vh2:eq(0) div a").text(); //First value
$("th.ms-vh2:eq(1) div a").text(); //Second value
关于jquery - 在有多个元素的 jquery 中使用 .next css 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36421780/