JS中,通过parseFloat(0)方法以及三元运算处理后,将原输入的值0置空了,请教大神是什么原因T^T…… JS中 parseFloat() 函数
JS\u4e2d\u5bf9input\u4e2d\u5185\u5bb9\u505a\u5224\u65ad\uff0c\u5982\u679c\u4e3a\u7a7a\uff0c\u5c31\u8ba9\u5176\u663e\u793a0\u9996\u5148\u9700\u8981div\u5e03\u5c40\uff0c\u5148\u9700\u8981\u5c06\u6574\u4f53\u7684\u6846\u67b6\u5e03\u5c40\u8d77\u6765\uff1a
\u5224\u65advar txt = document.getElementById('txt');txt.onblur = function(){if (txt.value == '') {txt.value = '0';}}
HTML\u6548\u679c\u7684\u622a\u56fe\u5982\u4e0b\uff1a
\u8fd9\u4e2a\u6548\u679c\u6700\u91cd\u8981\u7684\u4ee3\u7801\u5982\u4e0b\uff1a
var txt = document.getElementById('txt');
txt.onblur = function(){
if (txt.value == '') {
txt.value = '0';
}
}
4.\u5728\u6d4f\u89c8\u5668\u91cc\u9762\u6d4f\u89c8\u7684\u5982\u4e0b\uff1a
\u5b9a\u4e49\u548c\u7528\u6cd5parseFloat() \u51fd\u6570\u53ef\u89e3\u6790\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002\u8be5\u51fd\u6570\u6307\u5b9a\u5b57\u7b26\u4e32\u4e2d\u7684\u9996\u4e2a\u5b57\u7b26\u662f\u5426\u662f\u6570\u5b57\u3002\u5982\u679c\u662f\uff0c\u5219\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u89e3\u6790\uff0c\u76f4\u5230\u5230\u8fbe\u6570\u5b57\u7684\u672b\u7aef\u4e3a\u6b62\uff0c\u7136\u540e\u4ee5\u6570\u5b57\u8fd4\u56de\u8be5\u6570\u5b57\uff0c\u800c\u4e0d\u662f\u4f5c\u4e3a\u5b57\u7b26\u4e32\u3002\u8bed\u6cd5parseFloat(string)\u53c2\u6570\u63cf\u8ff0string \u5fc5\u9700\u3002\u8981\u88ab\u89e3\u6790\u7684\u5b57\u7b26\u4e32\u3002 \u8be6\u7ec6\u8bf4\u660eparseFloat \u662f\u5168\u5c40\u51fd\u6570\uff0c\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5bf9\u8c61\u3002parseFloat \u5c06\u5b83\u7684\u5b57\u7b26\u4e32\u53c2\u6570\u89e3\u6790\u6210\u4e3a\u6d6e\u70b9\u6570\u5e76\u8fd4\u56de\u3002\u5982\u679c\u5728\u89e3\u6790\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e86\u6b63\u8d1f\u53f7\uff08+ \u6216 -\uff09\u3001\u6570\u5b57 (0-9)\u3001\u5c0f\u6570\u70b9\uff0c\u6216\u8005\u79d1\u5b66\u8bb0\u6570\u6cd5\u4e2d\u7684\u6307\u6570\uff08e \u6216 E\uff09\u4ee5\u5916\u7684\u5b57\u7b26\uff0c\u5219\u5b83\u4f1a\u5ffd\u7565\u8be5\u5b57\u7b26\u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5b57\u7b26\uff0c\u8fd4\u56de\u5f53\u524d\u5df2\u7ecf\u89e3\u6790\u5230\u7684\u6d6e\u70b9\u6570\u3002\u540c\u65f6\u53c2\u6570\u5b57\u7b26\u4e32\u9996\u4f4d\u7684\u7a7a\u767d\u7b26\u4f1a\u88ab\u5ffd\u7565\u3002\u5982\u679c\u53c2\u6570\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u80fd\u88ab\u89e3\u6790\u6210\u4e3a\u6570\u5b57\uff0c\u5219 parseFloat \u8fd4\u56de NaN\u3002 document.write(parseFloat("10")) document.write(parseFloat("10.00")) document.write(parseFloat("10.33")) document.write(parseFloat("34 45 66")) document.write(parseFloat(" 60 ")) document.write(parseFloat("40 years")) document.write(parseFloat("He was 40"))\u8f93\u51fa\uff1a101010.33346040NaN
deductNum = $('#deductNum').val() == ""?0:parseFloat($('#deductNum').val());$("#deductNum").val(deductNum.toFixed(2));
扩展阅读:免费网站入口在哪 ... mac蜜桃奶茶314 ... www.sony.com.cn ... java入门网站 ... 免费excel永久免费版 ... 私人免费网站怎么下载 ... b站在线观看人数在哪 ... b站网外禁止转播 ... b站网页入口免费不收费 ...