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>
如果第二个跨度(值)是emty,则无法找到如何隐藏第一个跨度(作为标签)的解决方案。
代码用于创建打印页面表单。
答案 0 :(得分: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>