修正了模糊不想开火的问题
toFixed onBlur not wanting to fire?
我正试图使数字输入自动移位到小数点后2位-但经过几次尝试后,我不能得到这个去-和想法?:
html<tr>
<td colspan="2" class="null"></td>
<td class="label">Money Accounted For</td>
<td class="field"><input type="text" name="moneyAccountedFor" id="moneyAccountedFor" tabindex="7" /></td>
</tr>
JQuery $("#moneyAccountedFor").blur(function() {
$(this).val($(this).value.toFixed(2));
});
编辑:为了更仔细地查看我的问题—我创建了一个fiddle: http://jsfiddle.net/drewwyatt/AEWHs/
用this.value
代替$(this).value
:
$("#moneyAccountedFor").blur(function() {
this.value = this.value.toFixed(2);
});
或$(this).val()
如果你更喜欢jQuery'ish。
进一步的问题在于输入值类型。您需要通过parseFloat
, parseInt
或将其值解析为整数,否则…
$("#moneyAccountedFor").blur(function() {
this.value = parseInt(this.value).toFixed(2);
});
http://jsfiddle.net/AEWHs/2/我可以使用
让它工作<tr>
<td colspan="2" class="null"></td>
<td class="label">Money Accounted For</td>
<td class="field"><input type="text" name="moneyAccountedFor" id="moneyAccountedFor" onblur ="this.value = Number(this.value).toFixed(2)"></td>
</tr>
小提琴:
http://jsfiddle.net/drewwyatt/AEWHs/1/
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 将PHP变量传递给jQuery时遇到问题
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 参数变量出现ngTable指令问题
- 剑道网格jQuery动画()问题
- 我的jQuery插件参数没有正确启动,遇到了问题
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- TableExport jquery插件:文件名和扩展名问题
- JavaScript Pub/Sub属性访问问题
- JavaScript异步问题
- 如何解决Yii中的页面刷新问题
- Safari(Mac OS)上的jQuery平滑滚动问题
- jqGrid树网格问题
- 使用正则表达式评估电子邮件地址时出现性能问题
- 如何消除代码中的未定义和其他问题
- JavaScript代码问题:我正在将对象转换为数组
- 三星智能电视应用程序;Brightcove示例应用程序远程控制问题
- 由于iframe导致的问题
- ReactJS和SpringDataRest缓存问题可能与websocket有关
- 修正了模糊不想开火的问题