JS常用方法

2022-05-01 12:51:13 字數 1073 閱讀 4385

string.prototype用於為某字串物件新增方法

// 實現contains方法(核心是用index方法的返回值進行判斷)

string.prototype.contains = function (str) ;

// 字串替換

string.prototype.replace = function(oldvalue,newvalue) 

// 去掉字元兩端的空白字元

string.prototype.trim = function (s) ;

// 去掉字元結束的空白字元

string.prototype.trimend = function (s) return this; };

// 去掉字元開始的空白字元

string.prototype.trimstart = function (s) return this; };

// 判斷字串是否以指定的字串開始

string.prototype.startswith = function (str) ;

// 判斷字串是否以指定的字串結束

string.prototype.endswith = function (str) ;

string.prototype.remove = function (start, l)

string.prototype.insert = function (index, str)

string.prototype.gethashcode = function ()

// 返回字元的長度,乙個中文算2個

string.prototype.chineselength=function() return false; }

date.prototype.format = function (format) ; if (/(y+)/.test(format)) for (var k in o) } return format }

date.prototype.adddays = function (days)

date.prototype.diff = function (date)

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...