根据数组中的值隐藏和显示元素


Hiding and showing element on the basis of value in array

我有一个菜单栏 <a href="menu1" ">Menu1</a> <a href="menu2"">Menu 2</a> 对于这些菜单 1 和菜单 2,我存储了值 0110,依此类推。我有一个表,我在其中存储这些项目的值 1 和 ZERO。在其他页面上,我正在获取数组中的所有字段

for($i=1;$i<15;$i++)
    echo $check1[$i];

并得到与数据库中完全相同的 1010100.现在我想检查值是否为 1,该特定菜单应该显示在页面上,否则不会。现在我想做一个jquery或使用php隐藏值为0的元素并显示值为1的元素。我可以使用吗

for(var i=0;var i<15;i++)
{ 
    switch (var[i]){
        case 1:var[i].hide;
            break;
        case 2:var[i].show;
    }
}

提前谢谢你

你想切换 1 和 0?检查此代码:

    <script language="javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
    <table width="300" border="1" cellspacing="1" cellpadding="2">
      <tr>
        <td>Index</td>
        <td>1 / 0</td>
      </tr>
      <? for($i=1;$i<15;$i++){
        $value = rand(0,1);
      ?>
      <tr class="tr<?=$value;?>">
        <td><?=$i;?></td>
        <td><?=$value;?></td>
      </tr>
      <? } ?>
    </table>
    <a href="#" onclick="$('.tr0').show();$('.tr1').hide();">Show 0</a>
    |
    <a href="#" onclick="$('.tr1').show();$('.tr0').hide();">Show 1</a>
|
<a href="#" onclick="$('.tr1').show();$('.tr0').show();">Show both</a>