我有 id = "input-price"的输入和具有某些数值的元素范围,例如100.我希望输入中每输入一个字符,100的值就会增加10,而当我删除该字符时,该值就会减少10。如何做到这一点?
最佳答案
试试这个 -
var priceInput = document.getElementById("input-price");
priceInput.addEventListener("input", representValue)
function representValue(){
var numOfChars = priceInput.value.length;
var magicSpan = document.getElementById("magic-value");
value = 100 + (numOfChars*10);
magicSpan.textContent = value;
}
<span id="magic-value">100</span>
<input id="input-price" type="text">
关于javascript - js/jquery 在输入中输入文本时添加或删除值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54267253/