我在此页面上有一个可单击的 +/- 图标,当用户在 jsp 页面中单击该图标时,该图标将展开和折叠信息表,但问题是,如果用户使用 Tab 键切换到该图标并尝试展开/按下回车按钮将其折叠,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="-";
}
}
}
最佳答案
描述说:
当在元素上单击指点设备按钮时,会发生 onclick
事件。此属性可与大多数元素一起使用。
我认为您可以尝试使用表单的 onsubmit()
而不是 onclick()
。尝试一下..
关于图标上的 Javascript 无法使用 Enter 按钮来展开和折叠表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692206/