[英]Top items in javascript show/hide
我该怎么做,所以将显示“显示前10个项目”,当我单击它时,它将显示“隐藏前10个项目”
我的密码
// TOP 10 items
$results = mysql_query("SELECT items1, items2, items3 FROM items");
if (mysql_num_rows($results) > 0) {
print ("<a href=\"javascript: klappe_news('a4')\">Show Top 10 Items</a>
<div style='display:none'>
<table align='center' cellspacing='0' cellpadding='5'><tr>
<td>Items1</td>
<td>Items2</td>
<td>Items3</td>
</tr>");
while ($arr = mysql_fetch_assoc($results)) {
print ("<tr>
<td>".$arr['items1']."</td>
<td>".$arr['items2']."</td>
<td>".$arr['items3']."</td>
</tr>");
}
print("</table></div>");
} ?>
对于mysql,您必须使用类似的东西
$results = mysql_query("SELECT items1, items2, items3 FROM items LIMIT 10 ");
这必须使用jQuery或javascript完成。
// TOP 10 items
$results = mysql_query("SELECT items1, items2, items3 FROM items");
if (mysql_num_rows($results) > 0) {
//You have to add an id to <a> to access it with jQuery
//You also need to add an id to the div
print ("<a id="show_hide" href=\"javascript: klappe_news('a4')\">Show Top 10 Items</a>
<div id="table_container" style='display:none'>
<table align='center' cellspacing='0' cellpadding='5'><tr>
<td>Items1</td>
<td>Items2</td>
<td>Items3</td>
</tr>");
while ($arr = mysql_fetch_assoc($results)) {
print ("<tr>
<td>".$arr['items1']."</td>
<td>".$arr['items2']."</td>
<td>".$arr['items3']."</td>
</tr>");
}
print("</table></div>");
} ?>
<!-- Add jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
//Click event
$('#show_hide').click(function() {
//Hides the div with id table_container
$('#table_container').toggle();
//Checks if div with id table_container is visble, then it hides or shows it and changes the text
if($('#table_container').is(':visible'))
$(this).html('Hide Top 10 Items');
else
$(this).html('Show Top 10 Items');
});
</script>
您的页面可能有问题,因为您正在使用标签,每次单击它都会重新加载页面,因此您可能需要将其切换到div。
编辑:我忘了添加jQuery
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.