0

我正在尝试显示几个复选框的 onClick 或 onSelect 表。I have a checkbox for 'standard' which, when selected, should display a table of standard options, and I have a checkbox for 'customized' which, when selected, should display a table of customized options.

现在表格切换但不会同时显示。换句话说,如果两者都被选中,我需要显示两个表,一个在另一个之下。如果仅选中“标准”,则仅显示“标准”选项,如果仅选中“自定义”,则仅显示“自定义”选项。

这是一个小提琴:http: //jsfiddle.net/4tcRD/2/

这是我的 JS:

function toggleTables(which)
{

    if(which == "1") {
        document.getElementById('customize').style.display = "table";
        document.getElementById('standard').style.display = "none";

        }
    if(which == "2") {
        document.getElementById('standard').style.display = "table";
        document.getElementById('customize').style.display = "none";

        }
}

这是我的 HTML:

<input name="checkbox1" type="checkbox" id="customize_1" onClick="toggleTables('2')" value="checkbox" />
<label for="checkbox1"></label> Standard&nbsp;&nbsp;&nbsp;
<input name="checkbox2" type="checkbox" id="customize_0" onClick="toggleTables('1')" value="checkbox" checked="checked" />
Customize


<br />
<table width="100%" class="imagetable" cellpadding="0" cellspacing="0" id="customize">
    <tr><td>customize</td></tr>                   
</table>

<table width="100%" class="imagetable" cellpadding="0" cellspacing="0" id="standard" style="display: none">
    <tr><td>standard</td></tr>                   
</table>

请帮我一把。- 用复选框更新**

4

1 回答 1

2

可以只检查函数内复选框的状态。

function toggleTables()
{
    var isCustomize = document.getElementById('customize_1').checked; 
    var isStandard = document.getElementById('standard_1').checked;  

    var customize = document.getElementById('customize'); 
    var standard = document.getElementById('standard');    

    customize.style.display = isCustomize  ? 'table' : 'none';
    standard.style.display = isStandard  ? 'table' : 'none';
}​

http://jsfiddle.net/4tcRD/3/

于 2013-01-02T17:02:16.473 回答