簡體   English   中英

Onclick與同一個類別執行動作多個href

[英]Onclick perform action multple hrefs with same class

好的,我有一個for循環,可以從數據庫中獲取隨機數據。 我已經將這些值分配給我的href,如下所示:

<input type="text" class="form-control text-center no-left-border" maxlength="11" id="sellamount" name="sellamount" value="0" />
  <a href="<?php echo $buyOrders->amount; ?>" class="buyorderamount">

並在href單擊我希望href值進入我的復選框時,我正在使用以下代碼執行該操作:

 $(".buyorderamount").click(function(e)
  {
    e.preventDefault();
    $('#sellamount').val($('.buyorderamount').attr('href'));
    return false;
  });

只有第一個href會更新輸入,當我單擊鏈接2,3等時,它們不會更新輸入。

請您不要引用被點擊的那個

$('.buyorderamount').attr('href') <-- grabs all the elements and will return the first one

您需要獲得單擊的那個

$(this).attr('href')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM