这是我使用的 jquery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".post").hide();
$(".show_hide").show();
$(".show_hide").click(function(){
$(".post").slideToggle();
});
});
</script>
我正在使用 json api 来生成内容
<?php
$region_api = $_GET['server'];
if($region_api == 'euw')
$api = 'http://euw.leagueoflegends.com/board/devtracker.php?format=json';
elseif($region_api == 'eune')
$api = 'http://eune.leagueoflegends.com/board/devtracker.php?format=json';
elseif($region_api == 'na')
$api = 'http://na.leagueoflegends.com/board/devtracker.php?format=json';
$json_file = file_get_contents($api, null, null);
$json_array = json_decode($json_file, true);
?>
<div id="content">
<?php
foreach($json_array as $i =>$value){
$userid = $json_array[$i]['userid'];
$username = $json_array[$i]['username'];
$usertitle = $json_array[$i]['usertitle'];
$threadid = $json_array[$i]['threadid'];
$threadtitle = $json_array[$i]['threadtitle'];
$forumtitle = $json_array[$i]['forumtitle'];
$postid = $json_array[$i]['postid'];
$postcontent = $json_array[$i]['pagetext'];
$avatardateline = $json_array[$i]['avatardateline'];
?>
</br>
<a href="#" class="show_hide"><?php echo $threadtitle; ?></a>
<div class="post">
<div class="left">
<div class="user_info">
<div class="username">
<?php echo $username; ?></br>
<?php echo $usertitle; ?>
</div>
<div class="avatar"><img src='http://<?php echo $region_api;?>.leagueoflegends.com/board/image.php?u=<?php echo $userid; ?>&dateline=<?php echo $avatardateline; ?>'></div>
</div>
</div>
<div class="right">
<div class='post_text'><p><?php echo $postcontent; ?></p></div>
</div>
</div>
<?php
}
?>
</div>
<?php
?>
这可能不是最好的方法,但我在隐藏单个 div 时遇到了问题。相反,当您单击标题时,它会显示/隐藏所有 div 示例 http://leagueoflegends-bg.com/redtrack.php?server=euw#