私は、imgを含むdivを持つphpファイルを持っています。imgは私のデータベースから来ています。私は "次へ" btnをコードしたいので、配列をループして異なるimgを表示します。しかし、私はJQueryとPHPを使ってこれを行う方法を知らない。 Plzはいくつかの助けを与える。私はここで何をしたいのかTHX次のボタンを使ってループを突き抜けます。
<link href="../css-home/findgoods.css" rel="stylesheet"/>
<script src="../js/home-img.js" type="text/javascript"></script>
<?php if(is_array($goodsinfo)):?>
<div class="container">
<div style="display: inline-block;">
<img class="img-click" src="<?php echo $goodsinfo[$size] - >goods_pic?>"/>
</div>
<button id="call_back_btn">Next</button>
<textarea id="input"></textarea>
<textarea id="response"></textarea><!--
は、私は配列である私の$ goodsinfoループスルーできるように、私のPHPで値$サイズを変更することです。開始時に私は自分の無法の最初の画像を表示したいので、$ sizeを0にして、Nextボタンを押すと$ sizeが1になります。 2つのテキストボックスで試しましたが、次へをクリックすると変更されますが、AJAXから返された$サイズは変更されていないようです。
$(document).ready(function(){
$index = 0,
$itemAmt = 6,
$.post("../js/calculate_array.php",
{
size : $index,
},
function(data)
{
$('#response').val(data);
console.log(data);
}
);
$('#call_back_btn').click(function()
{
$index += 1;
if ($index > itemAmt - 1) {
$index = 0;
}
$.post("../js/calculate_array.php",
{
size : $index,
},
function(data)
{
$('#response').val(data);
console.log(data);
}
);
});
});
私のAjaxのファイル。
<?php
$size = $_POST['size'];
echo $size;
?>
間の遷移効果をしたい場合は、
hide
とshow
機能にいくつかの引数を渡すことができ、すべての画像が.active
クラスこんにちは、私は自分の投稿を更新しました。 –