我具有一个在保存更改之前解析所有错误字段的功能,我可以轻松获取错误字段标签的文本,但是我坚持获取包含冒号的ID:
var x = [],
y = [];
$('div.has-error label.control-label').each(function(index, obj) {
x.push($(this).text());
y.push($(this).prop('id'));
});
console.log(y.join('~'));
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="view:_id1:_id2:facetMiddle:ccSection3">
<div class="ccSectionPanel panel panel-default" id="pSection3">
<div style="cursor:pointer;" class="panel-heading" id="pSection3_heading" href="#pSection3_section" data-toggle="collapse">
<a id="view:_id1:_id2:facetMiddle:ccSection3:_id145" href="#" class="panel-title">Расположение</a></div>
<div class="panel-collapse collapse in" id="pSection3_section">
<div class="panel-body">
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody">
<div class="form-horizontal">
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgPostCode">
<div class="form-group required">
<label for="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgPostCode:fieldFacet:NumberPostCode" class="control-label col-xs-12 col-sm-4" id="fgPostCode_label">Индекс</label>
<div class="col-xs-12 col-sm-8">
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgPostCode:fieldFacet">
<input type="number" value="107392" id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgPostCode:fieldFacet:NumberPostCode" name="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgPostCode:fieldFacet:NumberPostCode" autocomplete="off" class="form-control"
placeholder="Индекс" min="100000" pattern="^\d{6}$" max="999999" maxlength="6" required=""></div>
</div>
</div>
</div>
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgAddress">
<div class="form-group required">
<label for="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgAddress:fieldFacet:TextAddress" class="control-label col-xs-12 col-sm-4" id="fgAddress_label">Адрес (юридический)</label>
<div class="col-xs-12 col-sm-8">
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgAddress:fieldFacet">
<input type="text" value="ул. Халтуринская, д.18" id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgAddress:fieldFacet:TextAddress" name="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgAddress:fieldFacet:TextAddress" autocomplete="off" class="form-control"
placeholder="Адрес (юридический)" required=""></div>
</div>
</div>
</div>
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict">
<div class="form-group required has-error has-danger">
<label for="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict:fieldFacet:ComboDistrict" class="control-label col-xs-12 col-sm-4" id="fgDistrict_label">Округ</label>
<div class="col-xs-12 col-sm-8">
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict:fieldFacet">
<div class="dijit dijitReset dijitInline dijitLeft dijitTextBox dijitComboBox dijitValidationTextBox" id="widget_view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict:fieldFacet:ComboDistrict" role="combobox" aria-haspopup="true" data-dojo-attach-point="_popupStateNode"
lang="ru" widgetid="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict:fieldFacet:ComboDistrict" aria-labelledby="fgDistrict_label" style="">
<div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" data-dojo-attach-point="_buttonNode" role="presentation"><input class="dijitReset dijitInputField dijitArrowButtonInner" value="▼ " type="text" tabindex="-1" readonly="readonly" role="button presentation" aria-hidden="true" required=""></div>
<div class="dijitReset dijitValidationContainer"><input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" value="Χ " type="text" tabindex="-1" readonly="readonly" role="presentation" required=""></div>
<div class="dijitReset dijitInputField dijitInputContainer"><input class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textbox,focusNode" role="textbox" aria-required="true" tabindex="0" id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict:fieldFacet:ComboDistrict"
value="" aria-invalid="false" required=""><input type="hidden" name="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgDistrict:fieldFacet:ComboDistrict" value=""></div>
</div>
</div>
</div>
</div>
</div>
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea">
<div class="form-group required has-error has-danger">
<label for="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea:fieldFacet:ComboArea" class="control-label col-xs-12 col-sm-4" id="fgArea_label">Район</label>
<div class="col-xs-12 col-sm-8">
<div id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea:fieldFacet">
<div class="dijit dijitReset dijitInline dijitLeft dijitTextBox dijitComboBox dijitValidationTextBox" id="widget_view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea:fieldFacet:ComboArea" role="combobox" aria-haspopup="true" data-dojo-attach-point="_popupStateNode"
lang="ru" widgetid="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea:fieldFacet:ComboArea" aria-labelledby="fgArea_label" style="">
<div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" data-dojo-attach-point="_buttonNode" role="presentation"><input class="dijitReset dijitInputField dijitArrowButtonInner" value="▼ " type="text" tabindex="-1" readonly="readonly" role="button presentation" aria-hidden="true" required=""></div>
<div class="dijitReset dijitValidationContainer"><input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" value="Χ " type="text" tabindex="-1" readonly="readonly" role="presentation" required=""></div>
<div class="dijitReset dijitInputField dijitInputContainer"><input class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textbox,focusNode" role="textbox" aria-required="true" tabindex="0" id="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea:fieldFacet:ComboArea"
value="" aria-invalid="false" required=""><input type="hidden" name="view:_id1:_id2:facetMiddle:ccSection3:panelBody:fgArea:fieldFacet:ComboArea" value=""></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
如何获取包含冒号的ID列表(以在错误块上创建链接)?
答案 0 :(得分:2)
您可以获得该元素的属性“ id”,
请检查我为您制作的小提琴。
https://jsfiddle.net/p1c0s45r/1/
for paragraph in document.paragraphs:
for run in paragraph.runs:
#print run.text
#print run._element.xml
run.text = 'translated text'