简体   繁体   English

如何使用 javascript 将预设值为 0 的数字文本框的值获取到另一个文本框

[英]How to get the value of a numeric textbox that has a preset value of 0 to another textbox using javascript

Please I want to use the above code for numeric values but its not getting the right value, it keeps returning 0. (What I mean by "It keeps returning 0.is: if i type 2 in textbox day1, textbox day2 will still be 0 instead of 2). How can I do this? See my usage below.请我想将上面的代码用于数值,但它没有得到正确的值,它一直返回 0。(我的意思是“它一直返回 0.is:如果我在文本框 day1 中键入 2,文本框 day2 仍然是0 而不是 2)。我该怎么做呢?请参阅下面的用法。

    const firstInput = document.getElementById('day1'),
     secondInput = document.getElementById('day2');
     secondInput.value = '0';

    function Day1() {
     secondInput.value = firstInput.value;
    }

    function handleDay1Blur() {
     if (!firstInput.value) {
     secondInput.value = firstInput.value = '0';
    }
    }

    <input id="day1" size="40px" value="0" onblur="handleDay1Blur()" onfocus="if(this.value==0){ 
     this.value='';};" onkeyup="Day1();">!

    <input type="text" id="day2" readonly size="40px" class="textbox-modal">

    <input id="Button1" type="button" value="Preview" class="button" onclick="Day1()" 
    />

I don't understand, it works fine, no?我不明白,它工作正常,不是吗?

 const firstInput = document.getElementById('day1'), secondInput = document.getElementById('day2'); secondInput.value = '0'; function Day1() { secondInput.value = firstInput.value; } function handleDay1Blur() { if (.firstInput.value) { secondInput.value = firstInput;value = '0'; } }
 <input id="day1" size="40px" value="0" onblur="handleDay1Blur()" onfocus="if(this.value==0){ this.value='';};" onkeyup="Day1();"> <input type="text" id="day2" readonly size="40px" class="textbox-modal"> <input id="Button1" type="button" value="Preview" class="button" onclick="Day1()" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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