【问题标题】:Modify javascript to work without form?修改javascript以在没有表单的情况下工作?
【发布时间】:2010-10-03 01:16:49
【问题描述】:

我想用它来隐藏/扩展列:
http://www.fiendish.demon.co.uk/html/javascript/hidetablecols.html
但删除与表格有关的所有内容。必须相应地更改 java 脚本函数,但我没有任何运气。有什么建议吗?
谢谢。

【问题讨论】:

  • “表格”是什么意思?复选框?否则,您将如何切换列?

标签: javascript html forms


【解决方案1】:

代码测试和工作。随时提出问题:)

<script language="javascript">

// Set the default "show" mode to that specified by W3C DOM
// compliant browsers

var showMode = 'table-cell';

// However, IE5 at least does not render table cells correctly
// using the style 'table-cell', but does when the style 'block'
// is used, so handle this

if (document.all) showMode='block';

// This is the function that actually does the manipulation

var States = { };

function toggleVis(col){

    if (!States[col] || States[col].IsOpen == null)
    {
        States[col] = {isOpen : true}; // This assumes the cell is already shown
    } 

    mode =  States[col].IsOpen ? showMode : 'none';

    cells = document.getElementsByName(col);
    for(j = 0; j < cells.length; j++) cells[j].style.display = mode;

    States[col].IsOpen = !States[col].IsOpen;
}

</script>

<a href="#" onclick="toggleVis('tcol1'); return false;">Toggle 1</a>
<a href="#" onclick="toggleVis('tcol2'); return false;">Toggle 2</a>
<a href="#" onclick="toggleVis('tcol3'); return false;">Toggle 3</a>
<a href="#" onclick="toggleVis('tcol4'); return false;">Toggle 3</a>

<table border=1>
<tr>
<td name="tcol1" class="bold">column 1 text</td>
<td name="tcol2" >column 2 text</td>
<td name="tcol3" class="italic">column 3 text</td>
<td name="tcol4" >column 4 text</td>
</tr>
<tr>
<td name="tcol1" class="bold">column 1 text</td>
<td name="tcol2" >column 2 text</td>
<td name="tcol3" class="italic">column 3 text</td>
<td name="tcol4" >column 4 text</td>
</tr>
</table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 2014-08-22
    相关资源
    最近更新 更多