gpt4 book ai didi

javascript - 单击事件不适用于由 JS 生成的按钮

转载 作者:行者123 更新时间:2023-11-30 14:01:45 25 4
gpt4 key购买 nike

<分区>

当我选择 "Keyboard layout" 时,它使用 js 生成按钮 - 但单击事件不适用于动态生成的按钮。我认为,这是因为当文档准备好时,元素“.prices-tier”不存在。它仅在我选择布局时生成。

enter image description here

我的部分代码:

    require(['jquery'], function(){
jQuery(document).ready(function(){
const currencySymbol = jQuery('.price').text()[0];
var standartPrice = Number(jQuery('.price-wrapper').attr('data-price-amount'));



jQuery('.prices-tier').on('click','.btn', function () {
var quantity = Number(jQuery(this).attr("data-qty"));
var price = jQuery(this).attr("data-amount");
jQuery('.qty-default').val(quantity);
jQuery('#product-price-'+"<?php echo $_product->getId();?>"+' .price').html(currencySymbol+price);
// jQuery('.product-info-main>div>.price-box>.price-container>.price-wrapper>.price').html(currencySymbol+price);
jQuery('.qty-default').trigger('input');
}
);

生成的html元素:

<div class="prices-tier items w-75 btn-group">

<button type="button" class="btn btn-light border border-bottom-0 border-top-0 bg-primary" data-qty="25" data-amount="27.21" onclick="">

4%</button>

<button type="button" class="btn btn-light border border-bottom-0 border-top-0 bg-primary" data-qty="50" data-amount="26.5" onclick="">

6%</button>
</div>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com