日期:2014-05-16 浏览次数:20385 次
<input type="submit" id="hideDiv" value="hide"> <input type="submit" id="showDiv" value="show"> <div id="div1">div11</div> <div id="div2">div12</div> <script type="text/javascript"> var arr = ['div1', 'div2']; $('#showDiv').click(function(){ $(arr).each(function(){ $('#' + this).show(); }); }); $('#hideDiv').click(function(){ $(arr).each(function(){ $('#' + this).hide(); }); }); </script>
------解决方案--------------------
<table> <tr class="pay0"> <td>1111</td> </tr> <tr class="pay1"> <td>1111</td> </tr> </table> <script type="text/javascript"> var arr = ["pay0","pay1"]; $('#showDiv').click(function(){ $(arr).each(function(){ $('tr.' + this).show(); }); }); $('#hideDiv').click(function(){ $(arr).each(function(){ $('tr.' + this).hide(); }); }); </script>