我有以下 javascript
function toggle_profile(source, target) {
var ele = document.getElementById(target);
var text = document.getElementById(source);
if (ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "+ ";
} else {
ele.style.display = "block";
text.innerHTML = "- ";
}
}
以下是在html中:
<c:forEach items="#{inventory.categories}" var="c">
<a id="#{c.name}" href="javascript:toggle_profile(#{c.name}, #{c.name}div);">+ </a>
<h:outputText value=" " />
<h:commandLink action="#{inventory.getBooks(c)}" value="#{c.name}" style="font-weight: bold" />
<br />
<div id="#{c.name}div" style="display: none">
<c:forEach items="#{c.subCategories}" var="s">
<i> <h:commandLink action="#{inventory.getBooks(s)}" value="#{s.name}" />
</i>
<br />
</c:forEach>
<br />
</div>
</c:forEach>
文本显示成功,但 + 链接不执行任何操作。