日期:2014-05-16  浏览次数:20357 次

有小数相减?
<form       name= "h ">      
    <input       type= "text "       name= "t1 "   onkeydown= "if(event.keyCode==13)event.keyCode=9 ">      
    + <input       type= "text "       name= "t2 "     onkeydown= "if(event.keyCode==13)event.keyCode=9 "       onBlur= "add() ">      
    = <input       type= "text "       name= "t3 "   onkeydown= "if(event.keyCode==13)event.keyCode=9 ">      
    </form>      
    <script       language= "javascript ">      
    function       add(){      
    document.h.t3.value       =     parseInt(document.h.t1.value)     -       parseInt(document.h.t2.value)      
    }      
    </script>


怎么实现:20.6-2.3=18.3

------解决方案--------------------
document.h.t3.value = parseFloat(document.h.t1.value) - parseFloat(document.h.t2.value)
------解决方案--------------------
<form name= "h ">
<input type= "text " name= "t1 " onkeydown= "if(event.keyCode==13)event.keyCode=9 ">
- <input type= "text " name= "t2 " onkeydown= "if(event.keyCode==13)event.keyCode=9 " onBlur= "add() ">
= <input type= "text " name= "t3 " onkeydown= "if(event.keyCode==13)event.keyCode=9 ">
</form>
<script language= "javascript ">
function add(){
document.h.t3.value = ( parseFloat(document.h.t1.value) - parseFloat(document.h.t2.value)) .toFixed(2)
//要约定保留几位小数,否则会出现12.3-2.6=9.700000000000001的情况
}
</script>