一个图标上的Javascript,用于展开和折叠不使用回车按钮的表

Javascript on a icon that expands and collapse a table not working with the enter button

本文关键字:折叠 按钮 回车 用于 一个 图标 Javascript      更新时间:2023-09-26

我在这个页面上有一个可点击的+/-图标,当用户在jsp页面中点击它时,它会展开和折叠一个信息表,但问题是,如果用户点击这个图标并尝试通过按enter按钮来展开/折叠它,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()。试一试。。