我正在嘗試在 PHP 和 Ajax 中使用 while 循環。但我只得到第一個 ID,沒有得到第二個、第三個等等。這是PHP的代碼:<div class="container pt-5 my-5"><section class="p-md-3 mx-md-5 text-center"> <h2 class="text-center mx-auto font-weight-bold mb-4 pb-2">Our Team</h2> <div class="row"> <?php while ($t_run=mysqli_fetch_array($t_query)){?> <div class="col-lg-3 col-md-4 col-sm-6 mb-4"> <div class="p-4"> <div class="avatar w-100 white d-flex justify-content-center align-items-center"> <input type="hidden" name="team" class='team_id' value="<?php echo $t_run['id']?>"> <img src='images/<?php echo $t_run['img']?>'class="team_img rounded-circle z-depth-1-half"/> </div> <div class="text-center mt-2"> <h6 class="font-weight-bold pt-2"><?php echo $t_run['name']?></h6> <p class="text-muted"> <small><i><?php echo $t_run['title']?></i></small> </p> <button class="team btn-info border-0 p-2 rounded">View profile</button> </div> </div> </div> <?php }?> </div></section>這是我使用的 Ajax 代碼<script type="text/javascript"> $(document).ready(function () { $('.team').click(function (){ var name = $('.team_id').val(); $('#content_container').load('team-ajex.php',{ id:name }); }); });</script>
1 回答
慕斯王
TA貢獻1864條經驗 獲得超2個贊
我建議你嘗試改變
$('.team_id').val()至
$(this).parent().parent().find('input[name="team"]').val()當您嘗試獲取$('.team_id')它時,它會返回一個包含此類所有輸入的數組...
- 1 回答
- 0 關注
- 144 瀏覽
添加回答
舉報
0/150
提交
取消
