1

HTML。我的代码如下所示:

<p class="left" style="margin-top: 0.5em;">
<span class="left">8. 1. pamatslimība</span>
<span style="float: right">
    <i data-openehr-field="/content[at0001]/items[lv.softdent.clinical::openEHR-EHR-ADMIN_ENTRY.izraksts.v1]/data/items[at0105]/items[at0106]" data-openehr-text-as-value="false" data-openehr-value-transformer="transformIcdTextToOnlyText"></i>
    <span data-openehr-field="/content[at0001]/items[lv.softdent.clinical::openEHR-EHR-ADMIN_ENTRY.izraksts.v1]/data/items[at0105]/items[at0106]" data-tmpl="#square" data-openehr-text-as-value="true"></span>
</span>
</p>

如果第二个跨度(值)为空,则无法找到如何隐藏第一个跨度(用作标签)的解决方案。

代码用于创建打印页面表单。

4

1 回答 1

1
<p class="left" style="margin-top: 0.5em;">
<span class="left hideIfSpanEmpty">8. 1. pamatslimība</span>
<span style="float: right">
    <i data-openehr-field="/content[at0001]/items[lv.softdent.clinical::openEHR-EHR-ADMIN_ENTRY.izraksts.v1]/data/items[at0105]/items[at0106]" data-openehr-text-as-value="false" data-openehr-value-transformer="transformIcdTextToOnlyText"></i>
    <span data-openehr-field="/content[at0001]/items[lv.softdent.clinical::openEHR-EHR-ADMIN_ENTRY.izraksts.v1]/data/items[at0105]/items[at0106]" data-tmpl="#square" data-openehr-text-as-value="true"></span>
</span>
</p>

用javascript找到解决方案

<script type="text/javascript">
function hideIfNextEmpty(el) {
  var text = 'textContent' in document ? 'textContent' : 'innerText';
  if (el.nextElementSibling[text].replace(/\s/g, '').length === 0) {
      el.style.display = 'none';
  }
}

var elements = document.getElementsByClassName("hideIfSpanEmpty");

for (var i = 0; i < elements.length; i++) {
hideIfNextEmpty(elements[i]);
}
</script>
于 2017-07-14T08:36:30.630 回答