Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 默认情况下,如果复选框已选中,则应隐藏HTML表_Javascript_Html_Jquery_Css - Fatal编程技术网

Javascript 默认情况下,如果复选框已选中,则应隐藏HTML表

Javascript 默认情况下,如果复选框已选中,则应隐藏HTML表,javascript,html,jquery,css,Javascript,Html,Jquery,Css,默认情况下,复选框已选中,但表未隐藏。默认情况下,应演示前两个表格。当您单击几次时,您可以看到隐藏的表,但它们应该作为默认选中项隐藏。我需要调用函数吗?还是需要更改函数中的参数 函数showMe(cls){ var chboxs=document.getElementsByName(“c1”); var-vis=0; 对于(变量i=0;i

默认情况下,复选框已选中,但表未隐藏。默认情况下,应演示前两个表格。当您单击几次时,您可以看到隐藏的表,但它们应该作为默认选中项隐藏。我需要调用函数吗?还是需要更改函数中的参数

函数showMe(cls){
var chboxs=document.getElementsByName(“c1”);
var-vis=0;
对于(变量i=0;i

显示结果
事件
地位
测试

不适用 测试

不适用 测试

不适用

1。测试输入:

不适用

1。期望

不适用

1。测试输入:

不适用

1。期望

不适用

1。测试输入:

不适用

1。期望

不适用
快速而肮脏的方法是在页面加载时调用
showMe('box')

函数showMe(cls){
var chboxs=document.getElementsByName(“c1”);
var-vis=0;
对于(变量i=0;i

显示结果
事件
地位
测试

不适用 测试

不适用 测试

不适用

1。测试输入:

不适用

1。期望

不适用

1。测试输入:

不适用

1。期望

不适用

1。测试输入:

不适用

1。期望

不适用
您可以找到详细信息,我准备了一个html文件。在javascript中调用showMe('box')时,它不起作用


函数showMe(cls){
var chboxs=document.getElementsByName(“c1”);
var-vis=0;
对于(变量i=0;i
显示结果
事件
地位
测试

不适用 测试

不适用 测试

不适用

1。测试输入:

不适用

1。期望

不适用

1。测试输入:

不适用

1。期望

不适用

1。测试输入:

不适用

1。期望

不适用
<script language="JavaScript">

function showMe(cls) {
    var chboxs = document.getElementsByName("c1");
    var vis = 0;
    for (var i = 0; i < chboxs.length; i++) {
        if (chboxs[i].checked) {
            vis = 1;
            break;
        }
    }
    var elements = document.getElementsByClassName(cls);
    for (let e of elements) {
        if (vis === 1) {
            e.style.display = 'none';
        } else {
            e.style.display = 'table';
        }

    }
}
show('box');
</script>

</head>


                <br>
                <table class="header" width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                <td align="left">
                <input type="checkbox" name="c1" checked="true" onclick="showMe('box')">Show Result
                </td>
                </tr>
                </table>
                
                <table class="uniqueborder" width="100%" bordercolor="#CBCBCB" cellpadding="0" cellspacing="0">
                <tr>
                <td class="uniqueborder" width="90%" align="center" bgcolor="#F3F3F3"><b>Event</b></td>
                <td class="uniqueborder" width="10%" align="center" bgcolor="#F3F3F3"><b>Status</b></td>
                </tr>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; ">Test </p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; ">Test </p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                </tbody></table>
                <table class="box" width="100%" bordercolor="#CBCBCB" cellpadding="0" cellspacing="0"><tbody>
                    <tr>
                        <td style="border-right:1px solid #CBCBCB; padding-left:2px; padding-right:2px"align="left"><p style="margin: 0pt; ">Test </p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>

                </tbody></table>
                <table class="box" width="100%" bordercolor="#CBCBCB" cellpadding="0" cellspacing="0"><tbody>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; "><span class="bluebold">1. Test input:</span></p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; "><span class="bluebold">1. Expected</span></p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                                    </tbody></table>
                <table class="uniqueborder" width="100%" bordercolor="#CBCBCB" cellpadding="0" cellspacing="0"><tbody>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; "><span class="bluebold">1. Test input:</span></p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; "><span class="bluebold">1. Expected</span></p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                                    </tbody></table>
                <table class="box" width="100%" bordercolor="#CBCBCB" cellpadding="0" cellspacing="0"><tbody>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; "><span class="bluebold">1. Test input:</span></p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                    <tr>
                        <td class="uniqueborder" align="left"><p style="margin: 0pt; "><span class="bluebold">1. Expected</span></p></td>
                          <td class="uniqueborder" align="center" width="10%"><font color="gray">N/A</font></td>
                    </tr>
                    
                </tbody></table></table>

</html>