简体   繁体   English

我想打破文本框的价值

[英]I want to break textbox value

I am using javascript to adding two textbox values and store that value in same textbox. 我正在使用JavaScript添加两个文本框值并将该值存储在同一文本框中。 For that process am using onmouseenter event. 为此,我使用了onmouseenter事件。 When i enter mouse in that textbox that textbox values increasing each time but i need to avoid it. 当我在该文本框中输入鼠标时,该文本框值每次都会增加,但我需要避免这种情况。 Here i posted my code can you please solve it, 我在这里发布了我的代码,您能解决吗?

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

HTML Code: 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> 

Use a flag to keep track of change 使用标记来跟踪更改

var allowChange = true;
function removeFormField() {          
    if(allowChange){
        var count_id = document.getElementById("balance").value;  
        document.getElementById('balance').value = parseInt(count_id)+10;
        allowChange = false;
    }   
}
<input type="text" class="form-control" id="balance" name="balance" placeholder="Balance amount" onkeypress="removeFormField()"> 

Only one change made on the input event. 输入事件仅发生一项更改。 Changed to keypress and it is only called when you enter and input to field. 更改为按键,仅在您输入并输入到字段时才调用。 and not when you click your mouse on to the field. 而不是单击鼠标到该字段时。

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

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