[英]How to add dollar sign to input field without affecting the value of input?
如何将$添加到以下输入中:
<td class="td10"><input type='text' class='form-control' id="boqRate" name="boq[boqRate]"></td>
尝试这个。 我添加了span元素与position:absolute
。
.prefix { margin-right: -10px; position: absolute; } .my-input { padding-left: 5px; }
<td class="td10"><span class="prefix">$</span><input class="my-input" type='text' class='form-control' id="boqRate" name="boq[boqRate]"></td>
这应该工作:
let input = document.getElementById("name"); input.addEventListener("keydown", () => { let inputValue = input.value; if (inputValue) { if (inputValue.charAt(0) === "$") { inputValue = inputValue.substring(1); } } let newValue = `$${inputValue}`; input.value = newValue; });
<input id="name" />
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.