如果我使用的是輸入框,如下所示:
<input type="number" value="00001" />
我怎樣才能使它在按下箭頭時變成00002而不是2?

謝謝!
uj5u.com熱心網友回復:
"00001" 或 "00002" 不是數字,但如果你仍然想這樣做,請考慮以下內容:
在左邊添加前導零的函式(num 是值,size 是字串的大小)
function padLeadingZeros(num, size) {
var s = num "";
while (s.length < size) s = "0" s;
return s;
}
然后:
$(function() {
$("input").change(function(e){ // If the value changes
e.preventDefault();
$(this).val(padLeadingZeros($(this).val(), 5)); //replace the value with the returned value of the function, 5 is size.
});
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/350019.html
標籤:javascript html 查询 形式 bootstrap-4
上一篇:ShuffleArray單擊處理程式事件幫助React
下一篇:如何為重復模式創建正則運算式?
