How to get old Value with onchange() event in text box

后端 未结 9 2346
一向
一向 2020-11-28 05:49

I have a text Box and a Value poplulated in it when page loads. Now If user chanegs any thing in text box, then I want to get the Changed Value(New Value) and Old Value but

9条回答
  •  感动是毒
    2020-11-28 06:25

    I am not sure, but maybe this logic would work.

    var d = 10;
    var prevDate = "";
    var x = 0;
    var oldVal = "";
    var func = function (d) {
        if (x == 0 && d != prevDate && prevDate == "") {
            oldVal = d;
            prevDate = d;
        }
        else if (x == 1 && prevDate != d) {
            oldVal = prevDate;
            prevDate = d;
        }
        console.log(oldVal);
        x = 1;
    };
    /*
             ============================================
             Try:
             func(2);
             func(3);
             func(4);
    */
    

提交回复
热议问题