js 常用方法

2021-08-29 15:26:36 字數 1324 閱讀 7262

//獲取乙個物件相當於左邊界的位置

function getabsoluteleft(ob)

var obj=ob;

var objleft=obj.offsetleft;

while(obj!=null&&obj.offsetparent!=null&&obj.offsetparent.tagname!="body")

return objleft;

}//當前物件相對於窗體頂部的高度

function getabsolutetop(ob)

var obj=ob;

var objtop=obj.offsettop;

while(obj!=null&&obj.offsetparent!=null&&obj.offsetparent.tagname!="body")

return objtop;

}//兩個數相加

function accadd(arg1,arg2) catch(e)

trycatch(e)

m=math.pow(10,math.max(r1,r2))

return (arg1*m+arg2*m)/m

}//兩個數相減

function subtr(arg1,arg2) catch(e)

trycatch(e)

m=math.pow(10,math.max(r1,r2));

//last modify by deeka

//動態控制精度長度

n=(r1>=r2)?r1:r2;

return ((arg1*m-arg2*m)/m).tofixed(n);

}//替換字元

//將"|" 替換為 "/"

var reg=/\|/g;

str = str.replace(reg,"\/");

整數:/^\d+(\.\d+)?$/

//js 模擬滑鼠事件

doclick("mar",event);

function doclick(linkid, e)

else if (document.createeventobject)

}

模擬物件的js寫法

function gettype(),,,

,,,,

];for(var i=0;i}

div居中**

js工具 js常用方法,js常用判斷方法

function obj id 根據id得到物件 function val id 根據id得到物件的值 function trim str 刪除左邊和右邊空格 function ltrim str 刪除左邊空格 function rtrim str 刪除右邊空格 function isempty s...

js 常用方法

驗證數字,保留一位小數 function one ele a za z u4e00 u9fa5 驗證固定 和手機 function checkphone e 2 9 0 9 0 9 if e.value.match re 1 3 4 5 8 0 9 d test e.value else 驗證身份證...

js 常用方法

c c.substring 1,c.length 有的話,從第二位開始取 if c.indexof nameeq 0 return false 清除cookie function clearcookie name 設定cookie function setcookie name,value,seco...