이 작은 라이브러리 https://github.com/frmlnd/frmlnd-current 를 사용하여 다른 통화로 장바구니 가격을 추가합니다.
가격 값을 다른 통화로 표시하는 방법은 다음과 같습니다.
<span class="crrnt-currency inline" data-crrnt-base="USD" data-crrnt-currencies="GBP">$100</span>
모두 잘 작동합니다!
그러나 우리는 페이지가 onlick 이벤트를 통해로드 된 후 다른 가격 옵션을 표시하려고 시도하고 있지만 변경이 나중에 DOM에서 발생하기 때문에 추가 환율이 발생하지 않습니다.
클릭 코드
$('.payment-option').on('click', 'label', function (e) {
e.preventDefault();
$('.order-summary .inner p').html($(this).data('product'));
$('.order-summary .total .right').html('<span class="crrnt-currency click" data-crrnt-base="USD" data-crrnt-currencies="GBP">' + $(this).data('amount') + '</span>');
});
무엇을해야합니까?
여기에 https://jsfiddle.net/mironomadic/hw1cbz0t/1/ 문제의 데모 샘플을 넣었습니다.
첫 번째로드에서 예상대로 GBP로 환전 가치를 얻지 만 GBP의 가격 1 또는 2 통화 가치를 클릭하면 실행되지 않습니다.
이 코드를 다음으로 변경하십시오.
$('.payment-option').on('click', 'label', function (e) {
e.preventDefault();
$('.order-summary .inner p').html($(this).data('product'));
$('.order-summary .total .right em').empty().html(`<span class="crrnt-currency inline" data-crrnt-base="USD" data-crrnt-currencies="GBP">${$(this).data("amount")} </span>`);
$('.crrnt-currency').current({
api: 'https://openexchangerates.org/api/latest.json?app_id=6851e9a79b90414b8a35d3776790f60d'
});
});
중요한 것은 current api
다시 전화하는 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다