亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 ajax 中使用 while 循環

在 ajax 中使用 while 循環

PHP
心有法竹 2022-11-12 13:13:43
我正在嘗試在 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')它時,它會返回一個包含此類所有輸入的數組...


查看完整回答
反對 回復 2022-11-12
  • 1 回答
  • 0 關注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號