简体   繁体   中英

How can I transform my this js code so that every property of an object get updated by an input value and radio button value?

I have an object with 3 properties (amount,date,type) .every time the object is called date updates automatically. Here is the code

var Transaction = function(amount, type) {
    this.amount = amount;
    this.type = type;
    this.date = (function() {
        var d = new Date();
        var minutes = d.getMinutes();
        var month = d.getMonth() +1;
        if (minutes<10) {
            return (d.getDate() + "/" + month + "/" + d.getFullYear() + " " + d.getHours() + ":" + "0" + minutes);
        } else {
            return (d.getDate() + "/" + month + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes);
        }
    })();

How can I set it up so that amount can receive the value of an html input field and type the value from radio buttons? I want to use pure JS

If an input field is passed it will take it's value otherwise just use the value passed

this.amount = amount.value || amount;
this.type = type.value || type;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM