我在这个页面上有一个可点击的 +/- 图标,当用户在 jsp 页面中点击它时,它会展开和折叠信息表,但问题是如果用户点击这个图标并尝试展开/折叠它按回车键,javascript 不会运行;由于某种原因,它仅适用于鼠标单击。这是我在jsp页面上的内容:
<td>
<a onclick="hideShowTable(${count}, this.id)" style="cursor:hand"
title="Expand/Collapse Table" tabindex="40"
id="eCTable${count}"
>+
</a>
</td>
在 js 文件中执行这个函数:
function hideShowTable(tableCounter, id)
{
//Loop through all rows of the month
for(i=1; i<=12; i++)
{
var tableElm = document.getElementById("tableMonth"+ i +"_"+tableCounter);
//Hide or show the div tag
if (tableElm .style.display == "block"){
tableElm .style.display = "none";
document.getElementById(id).innerText="+";
}
else{
tableElm .style.display = "block";
document.getElementById(id).innerText="-";
}
}
}