Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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 使用脚本删除并显示TD_Javascript_Jquery_Asp.net_Removeclass - Fatal编程技术网

Javascript 使用脚本删除并显示TD

Javascript 使用脚本删除并显示TD,javascript,jquery,asp.net,removeclass,Javascript,Jquery,Asp.net,Removeclass,你好,我正在为我的网站使用Asp.net,我想删除和隐藏带有class属性的特定td 这是我的html代码 <table> <tr> <td class="1"> 1 </td> <td class="1"> 1 </td> <td class="2"> 2 </td> <td class="2"> 2 </td> </tr> </table> 1.

你好,我正在为我的网站使用Asp.net,我想删除和隐藏带有class属性的特定td

这是我的html代码

<table>
<tr>
<td class="1"> 1 </td>
<td class="1"> 1 </td>
<td class="2"> 2 </td>
<td class="2"> 2 </td>
</tr>
</table>

1.
1.
2.
2.
现在我有两个按钮在我的网站命名为btn1和btn2

如果btn1为空,请单击 我想删除所有带有1的类,只显示带有2的类

如果btn2为空,请单击 我想删除所有带有2的类,只显示带有1的类

包含脚本

<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
参考资料

使用jQuery
.hide()
.show()
函数,如下所示:

<script type="text/javascript">
    $(document).ready(function() {
        $('#Button1').click(function () {
            $('.1').hide();
            $('.2').show();
        });

        $('#Button2').click(function () {
            $('.2').hide();
            $('.1').show();
        });
    });
</script>

<table>
    <tr>
        <td class="1">1</td>
        <td class="1">1</td>
        <td class="2">2</td>
        <td class="2">2</td>
    </tr>
</table>
<input type="button" id="Button1" value="Button 1" />
<input type="button" id="Button2" value="Button 2" />

$(文档).ready(函数(){
$('#按钮1')。单击(函数(){
$('.1').hide();
$('.2').show();
});
$('#按钮2')。单击(函数(){
$('.2').hide();
$('.1').show();
});
});
1.
1.
2.
2.

这是一个。

你试过什么吗?太好了。除了发布这个问题“移除并隐藏”之外,您在解决问题方面做了哪些努力?我想你的意思是,你只是想隐藏它们,这样,如果单击其他按钮,你会再次显示它们并隐藏其他按钮吗?(如果你真的删除了它们,它们就消失了,你需要将它们重新插入DOM中,以便再次显示它们。)你说的DOM是什么意思?阅读下面的答案,它们都向你展示了如何实现这一点。因为他们中的许多人都使用jQuery,所以您需要包括它的库:code.jQuery.com/jQuery-1.9.1.js“>。将它放在您的标记中,并享受使用jQuery的乐趣。
$('#btn1').click(function() {
    $('td.1').show();
    $('td.2').hide();
});
$('#btn2').click(function() {
    $('td.2').show();
    $('td.1').hide();
});
<script type="text/javascript">
    $(document).ready(function() {
        $('#Button1').click(function () {
            $('.1').hide();
            $('.2').show();
        });

        $('#Button2').click(function () {
            $('.2').hide();
            $('.1').show();
        });
    });
</script>

<table>
    <tr>
        <td class="1">1</td>
        <td class="1">1</td>
        <td class="2">2</td>
        <td class="2">2</td>
    </tr>
</table>
<input type="button" id="Button1" value="Button 1" />
<input type="button" id="Button2" value="Button 2" />