Javascript:: addEventListener on change 单选按钮无法使用 requirejs

Javascript:: addEventListener on change radio button not working using requirejs

Requirejs addEventListener on change 单选按钮在 magento 中不起作用

这里一切正常,只有一个问题,它不是输入单选字段的值和 ID,所以我认为 addEventListener DOMContentLoaded 在这里不起作用。

非常感谢 TIA 的帮助

这是js文件代码

define([
    "jquery",
    "domReady!"
], function($){
    "use strict";
        const myscript=function(){
            const profit = document.querySelector('input[name="rdmonths"]:checked').value;
            const id = document.querySelector('input[name="rdmonths"]:checked').id;
            const principal = document.querySelector('input[name="investment_calc"]').value;
            const time = id;
            const rate = profit/100;
            const n = 1;
        
            const compoundInterest = (p, t, r, n) => {
               const amount = p * (Math.pow((1 + (r / n)), t));
               return amount;
            };
        
            document.getElementById("total-amount").innerHTML = (compoundInterest(principal, time, rate, n).toFixed(2));   
            console.log(compoundInterest(principal, time, rate, n).toFixed(2));
        }
        
        document.addEventListener('DOMContentLoaded',()=>{
            document.querySelectorAll('input[type="radio"][name="rdmonths"]').forEach(input=>{
                input.addEventListener('click', myscript )
            })
        })

    return myscript;
});

只需添加单选按钮更改的点击功能

define([
    "jquery",
    "domReady!"
], function($){
    "use strict";
    return function myscript()
    {
        const profit = document.querySelector('input[name="rdmonths"]:checked').value;
            const id = document.querySelector('input[name="rdmonths"]:checked').id;
            const principal = document.querySelector('input[name="investment_calc"]').value;
            const time = id;
            const rate = profit/100;
            const n = 1;
        
            const compoundInterest = (p, t, r, n) => {
               const amount = p * (Math.pow((1 + (r / n)), t));
               return amount;
            };
            document.getElementById("total-amount").innerHTML = (compoundInterest(principal, time, rate, n).toFixed(2));               
        jQuery(".months").click(function(){
            const profit = document.querySelector('input[name="rdmonths"]:checked').value;
            const id = document.querySelector('input[name="rdmonths"]:checked').id;
            const principal = document.querySelector('input[name="investment_calc"]').value;
            const time = id;
            const rate = profit/100;
            const n = 1;
        
            const compoundInterest = (p, t, r, n) => {
               const amount = p * (Math.pow((1 + (r / n)), t));
               return amount;
            };
            document.getElementById("total-amount").innerHTML = (compoundInterest(principal, time, rate, n).toFixed(2));
          });
    }
});