我有一个领域:
<input type= number />
I d like to punch in 0.50
without it “correcting it” to 0.5
, so it would display 0.50
.
我有一个领域:
<input type= number />
I d like to punch in 0.50
without it “correcting it” to 0.5
, so it would display 0.50
.
我在此问题上几乎没有什么作用,并看着眼光。 它说,它必须是有效的浮动点。 。
The best representation of the number n as a floating point number is the string obtained from applying the JavaScript operator ToString to n.
这意味着,这一格式将始终与评估数字一致,然后使用Java文本,以达到这一数目。 因此,当时没有任何拖车。
因此,你不得不诉诸于 Java。 这一直截了当,因为document.getElementById(numInput ) = 0.50 ;
仍然得到更正,以0.5
,因此可在onchange
上启动的验证编号,在可以防止缺席行动的情况下,在内部启动。
This is the best solution I could come up with... it s a bit of a hack, and will need a bit of tweaking for robustness, but hopefully it ll do what you want:
var numInput = document.getElementById( numInput );
numInput.addEventListener( keypress , function () {
this.setAttribute( type , text );
});
numInput.addEventListener( click , function () {
this.setAttribute( type , number );
});
因此,如果用户希望通过打字进入编号,则将输入类型移至案文,但当他们点击时,用户会将其改成数字。
如果你总是想要拖车,不管用户类型如何,那么你就可以这样做:
var numInput = document.getElementById( numInput );
numInput.addEventListener( blur , function () {
if (this.value === ) {
return;
}
this.setAttribute( type , text );
if (this.value.indexOf( . ) === -1) {
this.value = this.value + .00 ;
}
while (this.value.indexOf( . ) > this.value.length - 3) {
this.value = this.value + 0 ;
}
});
numInput.addEventListener( focus , function () {
this.setAttribute( type , number );
});
<><>Edit>: 我认为,第二种解决办法更符合用户的期望,但这意味着,如果用户类型<代码>0.5<>>>>/代码>将被迫到<代码>0.50<<>>,则该解决办法取决于您的希望。
我随函附上关于(变化)的活动,以了解你希望掌握的零 s。
$( .number-input ).on( change , function(){
$(this).val(parseFloat($(this).val()).toFixed(2));
});
它只是从价值上看,将其投向浮标,将其推到小数点,并将其重新列为价值。
I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....
I have a div <div id="masterdiv"> which has several child <div>s. Example: <div id="masterdiv"> <div id="childdiv1" /> <div id="childdiv2" /> <div id="...
I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...
<form><input type="file" name="first" onchange="jsFunction(2);"> <input type="file" name="second" onchange="jsFunction(3);"</form> Possible to pass just numbers to the js ...
So I ve got a menu with a hover/selected state and it loads fine in IE6/IE7. However when I scroll down the page and put the element outside of the viewport and then back in I get a broken image! I ...
I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!