我的表单中有一个分类控件,如下所示:
http://i.imgur.com/0KeD1WZ.png
要求是根据DisplayName(MyTaxonomy)获取值(Test | 7d780b6d-7404-44fc-9614-9dcea4a42fcd)。
我试图使用下面的jQuery获取值,但没有机会......
jQuery('div[class="ms-taxonomy.ms-taxonomy-height.ms-long"][title^="MyTaxonomy"]');
jQuery('.ms-taxonomy.ms-taxonomy-height.ms-long').find('MyTaxonomy');
使用以下SPAN,我可以使用此值获取值,但SPAN上不包含DisplayName ...
jQuery('.ms-taxonomy.ms-taxonomy-height.ms-long').val()
<SPAN><SPAN id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00><INPUT name=ctl00$m$g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14$ctl00$ctl05$ctl00$ctl00$ctl00$ctl04$ctl00$ctl01 class="ms-taxonomy ms-taxonomy-height ms-long" id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl01 type=hidden value=Test|7d780b6d-7404-44fc-9614-9dcea4a42fcd>
请帮忙。
我已在下面发布了DOM代码。
<TD class=ms-formbody vAlign=top>
<!-- FieldName="MyTaxonomy"
FieldInternalName="VersionGroup"
FieldType="SPFieldTaxonomyFieldType"-->
<SPAN><SPAN id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00><INPUT name=ctl00$m$g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14$ctl00$ctl05$ctl00$ctl00$ctl00$ctl04$ctl00$ctl01 class="ms-taxonomy ms-taxonomy-height ms-long" id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl01 type=hidden value=Test|7d780b6d-7404-44fc-9614-9dcea4a42fcd>
<DIV class="ms-taxonomy ms-taxonomy-height ms-long" id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02 InputFieldId="ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl01" SspId="c8c11c5d-c1e6-4d9b-98f2-c1b3db293461" GroupId="00000000-0000-0000-0000-000000000000" TermSetId="f5318c5e-30a6-4cb8-834d-7a558304ad88" AnchorId="00000000-0000-0000-0000-000000000000" IsMulti="false" AllowFillIn="false" WidthCSS="ms-long" JavascriptOnValidation Lcid="1033" IsSpanTermSets="false" IsSpanTermStores="false" IsIgnoreFormatting="false" IsIncludeDeprecated="false" IsIncludeUnavailable="false" IsIncludeTermSetName="false" IsAddTerms="false" IsIncludePathData="false" IsUseCommaAsDelimiter="true" Disable="false" ExcludeKeyword="false" WebServiceUrl="http://zin506/sites/LenzeLFMF/_vti_bin/TaxonomyInternalService.json" FieldName="MyTaxonomy" FieldId="b38cb204-7ed3-4a1f-9810-e41bef7e6263" DisplayPickerButton="true" MinimumHeight="15" IsPercentWidth="false" IsUnvalidated="false" AdjustingHeight="false">
<DIV class="ms-taxonomy-control-holder ms-long" id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02controlHolder><IMG width=16 height=16 tabIndex=0 title="Browse for a valid choice" class=ms-taxonomy-browser-button alt="Browse for a valid choice" src="/_layouts/images/EMMCopyTerm.png">
<DIV title="MyTaxonomy" class=ms-taxonomy-fieldeditor style="HEIGHT: 18px; WIDTH: 362px" RteRedirect="ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02editableRegion">
<DIV class="ms-rtestate-write ms-taxonomy-writeableregion" id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02editableRegion role=textbox aria-haspopup=true contentEditable=true aria-autocomplete=both aria-multiline=true DisableRibbonCommands="True" AllowMultiLines="false" RestrictPasteToText="True"><SPAN title="" class=valid-text>Test</SPAN></DIV></DIV></DIV>
<DIV class="ms-taxonomy-suggestion-container ms-rtefocus-invalid ms-taxonomy-hidden" id=ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02suggestionsContainer unselectable="on" RteRedirect="ctl00_m_g_68795b6c_a6d2_4a5b_905c_3d35d5cf3a14_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl02editableRegion">
<DIV class=ms-taxonomy-suggestion-holder unselectable="on" needsNewRequest="false" addCreateNewWhileTrimming="false" isSpanTermSets="false"></DIV><IMG width=15 height=15 class=ms-taxonomy-panel-resizer src="/_layouts/images/CornerGrip.gif" unselectable="on"></DIV></DIV></SPAN></SPAN>MyTaxonomy </TD>
答案 0 :(得分:1)
请尝试以下代码:
jQuery('.ms-formlabel nobr:contains"MyTaxonomy"').closest('tr').find('td.ms-formbody input:hidden').val();
答案 1 :(得分:1)
如果您只需要字段值
,则可以使用:$("div[title='MyTaxonomy']").text()
答案 2 :(得分:0)
function GetSectionForField(internalName) {
var found = null;
// Look into all td with the .ms-formbody class
var abc = jQuery('.td.ms-formbody').val();
jQuery("td.ms-formbody").each(function () {
var html = jQuery(this).html().replace(/\n/g, '');
//Check if it contains the keyword
if (html.indexOf('FieldName="') < 0) return;
var start = html.indexOf('FieldName="') + 'FieldName="'.length;
html = html.substring(start);
var stopp = html.indexOf('"');
var nm = html.substring(0, stopp);
// if is the internal name we are looking for
if (nm == internalName) {
var elements = jQuery(html);
found = jQuery('.ms-taxonomy.ms-taxonomy-height.ms-long', elements).val();
return found;
}
});
return found;
}
答案 3 :(得分:0)
jQuery('。ms-formlabel nobr:contains(“Taxonomy field Display Name”)')。nearest('tr')。find('td.ms-formbody input:hidden')。val(); < / p>
给出如下值:
分类标准值| 089d95ce-d97c-4f46-8cc1-fdd44ce696f7
现在你可以拆分|并获得值