0

我在这个页面上有一个可点击的 +/- 图标,当用户在 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="-";
    }

}

}

4

1 回答 1

1

描述说:

onclick当指针设备按钮在元素上单击时发生该事件。此属性可用于大多数元素。

我认为您可以尝试使用表单onsubmit()而不是onclick(). 试一下..

于 2013-02-04T17:52:18.197 回答