[英]JQuery - show div and all child label elements
My HTML: 我的HTML:
<div id="summarySpan" style="padding-left: 20px" hidden>
<label id="currentStatusSummary" style="padding-left: 20px" />
<br />
<label id="currentMonitoringSummary" style="padding-left: 20px" />
</div>
Javascript code: JavaScript代码:
$("#currentStatusSummary").text(returnedData.CurrentStatusSummary);
$("#currentMonitoringSummary").text(returnedData.CurrentMonitoringSummary);
$("#summarySpan").show().children().show();
For a reason I am unfamiliar with, only the first label (with ID currentStatusSummary) is shown when the JS code executes. 由于我不熟悉的原因,当执行JS代码时,仅显示第一个标签(ID为currentStatusSummary)。
Can someone please explain the reason for this and help me resolve it? 有人可以解释原因并帮助我解决吗?
First, hidden
is an invalid attribute. 首先, hidden
是无效属性。 Secondly, you should probably close your label
tags. 其次,您可能应该关闭label
标签。 Finally, you only need to hide and show the parent element (if the container is hidden, its content is too). 最后,您只需要隐藏并显示父元素(如果容器是隐藏的,则其内容也是如此)。
<div id="summarySpan" style="padding-left: 20px; display: none;">
<label id="currentStatusSummary" style="padding-left: 20px"></label>
<br />
<label id="currentMonitoringSummary" style="padding-left: 20px"></label>
</div>
$("#currentStatusSummary").text(returnedData.CurrentStatusSummary);
$("#currentMonitoringSummary").text(returnedData.CurrentMonitoringSummary);
$("#summarySpan").show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.