菜单默认应隐藏

时间:2013-08-23 09:43:43

标签: php javascript

嘿伙计们我希望默认情况下隐藏传感器,当我点击特定节点时它会显示...并且应该在页面重新加载时显示 这是我的代码

<ul >
<?php if(isset($nodes)): ?>
<?php $count = 0; ?>
<?php foreach($nodes as $node) { ?>
<?php $node_id=$node['node_id']; ?>
<?php $sensors = config_sensor_model::getsensors($node_id); ?>
<?php $count++; ?>
<li onclick="menu(<?php echo $count; ?>)"><a href="#"><?php echo $node['node_name']; ?> </a></li>
<ul id="<?php echo "sub_".$count; ?>">
<?php foreach($sensors as $sensorlog) { ?> 
<li><a href="<?php echo site_url(); ?>/dashboard/dashboard_graph/?node=<?php echo $node['node_id']; ?>&sensor=<?php echo $sensorlog->sensor_index; ?>&range=0&xticker=2&plot_graphs_value=1">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $sensorlog->sensor_name; ?></a></li>
<?php } ?>
</ul>           
<?php } ?>
<?php endif; ?>
</ul>
</div>

这是我正在使用的javascript

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script> 
function menu(count)
{
 $("#sub_"+count).toggle("fast");
}
</script>

2 个答案:

答案 0 :(得分:0)

style='display:none'

设置<ul>

答案 1 :(得分:0)

正如我的评论中所提到的那样,最初使用CSS来隐藏节点:

<style type="text/css">
    .hidden { display: none; }
</style>

<ul>
if(isset($nodes)):
    $count = 0;
    foreach($nodes as $node) {
        $node_id = $node['node_id'];
        $sensors = config_sensor_model::getsensors($node_id);
        $count++;
        ?>
        <li onclick="menu(<?php echo $count; ?>)"><a href="#"><?php echo $node['node_name']; ?> </a></li>
        <ul id="<?php echo "sub_".$count; ?>" class="hidden">
            <?php foreach($sensors as $sensorlog) { ?>
                <li><a href="<?php echo site_url(); ?>/dashboard/dashboard_graph/?node=<?php echo $node['node_id']; ?>&sensor=<?php echo $sensorlog->sensor_index; ?>&range=0&xticker=2&plot_graphs_value=1">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $sensorlog->sensor_name; ?></a></li>
            <?php } ?>
        </ul>           
    <?php }
endif; ?>
</ul>
</div>

单击菜单时,Javascript将切换display值。