我正在尝试在 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 关注
- 164 浏览
添加回答
举报
0/150
提交
取消
