0

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

<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>
4

2 回答 2

0

设置style='display:none'<ul>

于 2013-08-23T09:48:47.057 回答
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>

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

于 2013-08-23T09:51:43.170 回答