Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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/1/php/233.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 是否单击按钮隐藏/取消隐藏表格行?_Javascript_Php - Fatal编程技术网

Javascript 是否单击按钮隐藏/取消隐藏表格行?

Javascript 是否单击按钮隐藏/取消隐藏表格行?,javascript,php,Javascript,Php,我正在使用下面的代码 功能测试显示测试{ 如果document.getElementByIdportests.value==隐藏+测试{ document.getElementByIdportests.value=显示+测试; } 否则{ document.getElementByIdportests.value=隐藏+测试; } } 名字 姓氏 年龄 吉尔 史密斯 50 前夕 杰克逊 94 约翰 雌鹿 80 约翰 雌鹿 80 使用名为hide的变量。默认情况下,它设置为false。无论何时单

我正在使用下面的代码

功能测试显示测试{ 如果document.getElementByIdportests.value==隐藏+测试{ document.getElementByIdportests.value=显示+测试; } 否则{ document.getElementByIdportests.value=隐藏+测试; } } 名字 姓氏 年龄 吉尔 史密斯 50 前夕 杰克逊 94 约翰 雌鹿 80 约翰 雌鹿 80
使用名为hide的变量。默认情况下,它设置为false。无论何时单击按钮,功能toggleTable都将运行,这将检查hidevariable并将表的显示设置为ether block或none

JS

HTML


JS Fiddle:

试试看,这可能对你有帮助

<script>
    $(document).ready(function(){
        $('#portests').on('click',function(){   
        $('.test').toggle();
   });
});
</script>

<input type = "button" name = "Test1" id="portests" value = "test1" >
<input type = "button" name = "Test1" id="portests1" value = "test" >

<table style="width:100%" id="testing">
    <tr>
        <th>Firstname</th>
        <th>Lastname</th> 
        <th>Age</th>
    </tr>
    <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
    </tr>
    <tr class="test">
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
    </tr>
    <tr class="test">
        <td>John</td>
        <td>Doe</td>
        <td>80</td>
    </tr>
    <tr class="test">
        <td>John</td>
        <td>Doe</td>
        <td>80</td>
    </tr>
</table>
以下是JSFIDLE:

如果需要JAVASCRIPT,请尝试以下方法:

功能测试显示测试{ 如果document.getElementByIdportests.value==隐藏+测试{ document.getElementByIdportests.value=显示+测试; var table=document.getElementByIdtesting; 对于变量i=0,行;行=表。行[i];i++{ ifrow.className==test{row.style.visibility=hidden;} } } 否则{ document.getElementByIdportests.value=隐藏+测试; var table=document.getElementByIdtesting; 对于变量i=0,行;行=表。行[i];i++{ ifrow.className==测试{row.style.visibility='visible';} } } } 名字 姓氏 年龄 吉尔 史密斯 50 前夕 杰克逊 94 约翰 雌鹿 80 约翰 雌鹿 80
注意,这个问题与Java或jQuery无关。我重新标记了它,以便为您添加Javascript,而不是标题。您的问题真的不清楚,请详细说明!他要求的是Javascript,而不是jQuery@Finiox,我想你是blind@Finiox我想他想要的是,当你点击按钮时,隐藏有类的行test@Suchit我认为您也是瞎子,这就是为什么您不能在JSFIDLE上看到jquery文件的原因。@Suchit我已经测试过了。
<button type="button" onclick="toggleTable()"></button>

<table id="table">

</table>
<input type = "button" name = "show" id="show" value = "test1" onclick = "show()">
<input type = "button" name = "hide" id="hide" value = "test" onclick = "hide()">

function show() {
    $('#testing').show();
}
function hide(){
   $('#settings').hide();
}
<script>
    $(document).ready(function(){
        $('#portests').on('click',function(){   
        $('.test').toggle();
   });
});
</script>

<input type = "button" name = "Test1" id="portests" value = "test1" >
<input type = "button" name = "Test1" id="portests1" value = "test" >

<table style="width:100%" id="testing">
    <tr>
        <th>Firstname</th>
        <th>Lastname</th> 
        <th>Age</th>
    </tr>
    <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
    </tr>
    <tr class="test">
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
    </tr>
    <tr class="test">
        <td>John</td>
        <td>Doe</td>
        <td>80</td>
    </tr>
    <tr class="test">
        <td>John</td>
        <td>Doe</td>
        <td>80</td>
    </tr>
</table>