1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| var oInput1 = document.getElementById("input1"); var oInput2 = document.getElementById("input2"); var oSpan = document.getElementById("span"); var obj = {}; Object.defineProperties(obj, { val1: { configurable: true, get: function () { oInput1.value = 0; oInput2.value = 0; oSpan.innerHTML = 0; return 0; }, set: function (newValue) { oInput2.value = newValue; oSpan.innerHTML = Number(newValue) ? Number(newValue) : 0; }, }, val2: { configurable: true, get: function () { oInput1.value = 0; oInput2.value = 0; oSpan.innerHTML = 0; return 0; }, set: function (newValue) { oInput1.value = newValue; oSpan.innerHTML = Number(newValue) + 1; }, }, }); oInput1.value = obj.val1; oInput1.addEventListener( "keyup", function () { obj.val1 = oInput1.value; }, false ); oInput2.addEventListener( "keyup", function () { obj.val2 = oInput2.value; }, false );
|