[英]Hiding / Showing a Table with JavaScript
hi i have atable with some data and i have expand and Collapse button there if we click on + it will expand and show table and if we click on-it will collapse and i am using following code but i am getting error with 您好,我有一些数据,我有扩展和折叠按钮,如果我们单击+它将展开并显示表格,如果我们单击它会折叠,并且我正在使用以下代码,但是我遇到了错误
document.getElementById('eleName');
imageXchk='expand';
loadedCheck='false';
function toggleDisplayCheck(e, tableSize){
element = document.getElementById(e).style;
if (element.display=='none') {
element.display='block';
}
else {
element.display='none';
}
if (loadedCheck=='false') {
myUpdater('returnsDetailsTable', '/oasis/faces/merchant/dashboard/ReturnsDetailsCheck.jsp', { method: 'get' });
loadedCheck='true'
}
size = tableSize-1;
eleName = 'mercPerfDashboardForm:returnsDetailsTable:' + size +':switchimageRetChk'
if (imageXchk=='collapse') {
document.getElementById('eleName').src='${pageContext.request.contextPath}/images/expand.gif';imageXchk='expand';
}
else {
document.getElementById('eleName').src='${pageContext.request.contextPath}/images/collapse.gif';imageXchk='collapse';
}
return false;
}
If the element's style's display
property hasn't been explicitly set previously in JavaScript, it will be empty, even if the element is hidden via some CSS rule. 如果以前未在JavaScript中显式设置元素的样式的
display
属性,则该元素将为空,即使该元素已通过某些CSS规则隐藏。 The easiest thing to do would be to know what the initial state (hidden or visible) is and assume that state if the display
property is empty: 最简单的方法是知道初始状态(隐藏或可见)是什么,如果
display
属性为空,则假定该状态为:
if (element.display=='none' || element.display=='') {
element.display='block';
}
else {
element.display='none';
}
you can use jQuery to do this very very simple: 您可以使用jQuery非常简单地执行此操作:
$("#table_id").hide(); // hide the table
$("#table_id").show(); // show the table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.