js 失去焦點自動計算BMI 保留一位小數

2021-09-05 11:33:29 字數 697 閱讀 1441

一:

$("#height").blur(function() );

$("#height").blur(function() );

function calbmi(formid)

// 根據身高、體重計算bmi值

function caculatebmi(height, weight)

return bmi;

}二:注意問題

1  tofixed缺陷:它是乙個四捨六入五成雙的詭異的方法,"四捨六入五成雙"含義:

4舍6入5湊偶」這裡「四」是指≤4 時捨去,"六"是指≥6時進上,"五"指的是根據5後面的數字來定,當5後有數時,舍5入1;當5後   無有效數字時,需要分兩種情況來講:①5前為奇數,舍5入1;②5前為偶數,舍5不進。(0是偶數)

(119-116)*0.005 = 0.015  -------0.01

2math.round()缺陷:

0.095,四捨五入就變成了0.1了,而業務需求是小數點後面兩位,也就是0.10;

math.round((119-116)*0.005*100)/100;

最終兩者結合:

(math.round((119-116)*0.005*100)/100).tofixed(2);

失去焦點和獲得焦點發生事件 js

失去焦點 nblur hanshu this 獲得焦點 nf cus hanshu this 函式名 chksafe 功能介紹 檢查是否含有 引數說明 要檢查的字串 返回值 0 是1 不是 function chksafe a return 1 函式名 chkspc 功能介紹 檢查是否含有空格 引數...

js獲取焦點和失去焦點操作(模仿京東搜尋框)

doctype html utf 8 x ua compatible content ie edge dom2 title viewport content width device width,initial scale 1 stylesheet type text css media scree...

js 各種事件 如 點選事件 失去焦點 鍵盤事件等

事件驅動 我們點選按鈕 按鈕去掉用相應的方法。demo function func 事件 onclick 點選 onblur 失去焦點 onfocus 得到焦點 onkeydown 按下鍵盤 onkeyup 鬆開鍵盤 onkepress 按住鍵盤 onmousedown 按下滑鼠 onmouseup...