数据应该只显示与我单击的按钮有关的信息

Data should display only with respect to the button i clicked

本文关键字:按钮 信息 单击 显示 数据      更新时间:2023-09-26

我在一个表中有六个按钮,单击每个按钮后,与按钮相关的数据应该会显示,如果我单击另一个按钮,则以前的数据应该消失,只显示与该按钮有关的数据。我正在使用div。请帮我怎么做。

您可以先隐藏div,然后根据按钮Id显示。请参阅Fiddle

$("#bt1").click(function(){
$(".hide").hide();
$("#id1").show();
})
$("#bt2").click(function(){
$(".hide").hide();
$("#id2").show();
})
$("#bt3").click(function(){
$(".hide").hide();
$("#id3").show();
})
.hide{display:none}
<table>
    <tr>
        <td><button type="button" id="bt1">button1</button></td>
         <td><button type="button" id="bt2">button2</button></td>
         <td><button type="button" id="bt3">button3</button></td>
    </tr>
</table>
<div id="id1" class="hide">Button1</div>
<div id="id2"  class="hide">Button2</div>
<div id="id3"  class="hide">Button3</div>

https://jsfiddle.net/zgwugk5y/3/