如何让php读一组图片,每页显示20张,排成5x4矩形,然后每个照片下面加红心,点红心后数字+1.
2个回答
展开全部
<body>
<?php
$pic = array('1.jpg','1.jpg','1.jpg','1.jpg','1.jpg','1.jpg','1.jpg','1.jpg');
$num = 0;
?>
<table>
<tr>
<?php
foreach($pic as $v){
$num++;
?>
<td>
<img src="<?php echo $v;?>" id="<?php echo $num;?>"/><br />
111 <a href="javascript:;" onclick="xh(<?php echo $num;?>)"><img src="2.jpg"/></a><span id="count<?php echo $num;?>">0</span>
</td>
<?php
if($num%5==0){
?>
</tr><tr>
<?php
}
}
?>
</tr>
</table>
</body>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function xh(id){
var count = document.getElementById('count'+id).innerHTML;
$.ajax({
type:'POST',
url:'dopic.php',
dataType:"json",
data:{id:id,count:count},
success:xh_response
});
}
function xh_response(result){
document.getElementById('count'+result.id).innerHTML=result.count;
}
</script>
在 dopic.php文件里:
<?php
$id = $_POST['id'];
$count = $_POST['count'];
$count++;
$result['id'] = $id;
$result['count'] = $count;
echo json_encode($result);
?>
分页啥的就自己去弄吧,就是加几个判断而已
<?php
$pic = array('1.jpg','1.jpg','1.jpg','1.jpg','1.jpg','1.jpg','1.jpg','1.jpg');
$num = 0;
?>
<table>
<tr>
<?php
foreach($pic as $v){
$num++;
?>
<td>
<img src="<?php echo $v;?>" id="<?php echo $num;?>"/><br />
111 <a href="javascript:;" onclick="xh(<?php echo $num;?>)"><img src="2.jpg"/></a><span id="count<?php echo $num;?>">0</span>
</td>
<?php
if($num%5==0){
?>
</tr><tr>
<?php
}
}
?>
</tr>
</table>
</body>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function xh(id){
var count = document.getElementById('count'+id).innerHTML;
$.ajax({
type:'POST',
url:'dopic.php',
dataType:"json",
data:{id:id,count:count},
success:xh_response
});
}
function xh_response(result){
document.getElementById('count'+result.id).innerHTML=result.count;
}
</script>
在 dopic.php文件里:
<?php
$id = $_POST['id'];
$count = $_POST['count'];
$count++;
$result['id'] = $id;
$result['count'] = $count;
echo json_encode($result);
?>
分页啥的就自己去弄吧,就是加几个判断而已
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询