我正在使用 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/