我在页面上有一个div,它显示了mysql DB中的客户端列表。默认情况下,它显示前10个。当用户单击“全部查看”时,jquery函数会重新加载div以显示div上的完整客户端列表。这部分工作正常。
但我还希望能够在用户点击“查看更少”时再次隐藏额外的客户端,只显示原始的10.这部分根本不起作用,我不知道为什么......
这是我第一次使用jquery进行编码,所以提前感谢您的帮助
HTML:
<div id="widgetbox" class="client shadow">
<?php include('include_clientwidget.php'); ?>
</div>
PHP(include_clientwidget.php):
<?php
// Connect to DB
include_once "connect_to_mysql.php";
echo '
<h3>Clients</h3>
<!--
';
$mode = $_GET['mode'];
if($mode=='all') {
$result = mysql_query("
SELECT
*
FROM
project_client
WHERE
active='1' AND
remove='0'
ORDER BY
new_project_date
");
}
else {
$result = mysql_query("
SELECT
*
FROM
project_client
WHERE
active='1' AND
remove='0'
ORDER BY
new_project_date
LIMIT
2
");
}
while ($row = mysql_fetch_array($result)) {
echo '
--><a href="#"><div id="tags">
' . $row['name'] . '
</div></a><!--
';
}
if($mode=='all') {
echo '
-->
<div id="clear"></div>
<a href="javascript:void(0);">
<div id="more" class="see_less">
See less
</div>
</a>
';
}
else {
echo '
-->
<div id="clear"></div>
<a href="javascript:void(0);">
<div id="more" class="see_all">
See all
</div>
</a>
';
}?>
jQuery的:
<script>
function showAllClient() {
$(".client").load("include_clientwidget.php?mode=all")
}
function showSomeClient() {
$(".client").load("include_header.php")
}
$('.see_all').on('click' , showAllClient);
$('.see_less').on('click' , showSomeClient);
</script>