javascript - 我想打破文本框的值

标签 javascript html

我正在使用 javascript 添加两个文本框值并将该值存储在同一个文本框中。对于该过程,我使用 onmouseenter 事件。当我在该文本框中输入鼠标时,文本框值每次都会增加,但我需要避免它。我在这里发布了我的代码,请您解决它,

function removeFormField() {          
        var count_id = document.getElementById("balance").value;  
        document.getElementById('balance').value = parseInt(count_id)+10;   
}

HTML 代码:

<div class="form-group">
     <label for="firstname" class="col-sm-4 control-label">Balance amount</label> 
        <div class="col-sm-6"> 
            <input type="text" class="form-control" id="balance" name="balance" placeholder="Balance amount" onmouseenter="removeFormField();"> 
        </div> 
</div> 

最佳答案

使用标志来跟踪更改

var allowChange = true;
function removeFormField() {          
    if(allowChange){
        var count_id = document.getElementById("balance").value;  
        document.getElementById('balance').value = parseInt(count_id)+10;
        allowChange = false;
    }   
}

关于javascript - 我想打破文本框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36027101/

相关文章:

javascript - 网页幻灯片 : Change position, 导航箭头的不透明度和样式

javascript - 如何防止在使用.val()时引入XSS漏洞?

javascript - 在动态添加元素时刷新 html

javascript - github 中的 Codacy 功能给了我一些我无法理解的错误

javascript - $inc 查询的 Nodejs 和 Mongoose 呈现路径

html - 垂直居中 <a> 标签?

html - 当所述导航栏设置为位置 :fixed; 时,下拉菜单在导航栏中无法正常工作

javascript - 掷骰子计数器,当玩家正好掷到 21 时获胜

html - 如何将 "div"固定在中心?

html - 停止在超棒的字体图标周围环绕文字