国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript 函數原型

2019-11-18 11:30:53
字體:
來源:轉載
供稿:網友

string .length 漢字為兩個字符處理
.Tlength



<script>
/*
 This following code are designed and writen by Windy_sk <seasonx@163.net>
 You can use it freely, but u must held all the copyright items!
*/

//測字符串實際長度
String.PRototype.Tlength = function(){var arr=this.match(/[^/x00-/xff]/ig);return this.length+(arr==null?0:arr.length);}

//字符串左取
String.prototype.left = function(num,mode){if(!//d+/.test(num))return(this);var str = this.substr(0,num);if(!mode) return str;var n = str.Tlength() - str.length;num = num - parseInt(n/2);return this.substr(0,num);}

//字符串右取
String.prototype.right = function(num,mode){if(!//d+/.test(num))return(this);var str = this.substr(this.length-num);if(!mode) return str;var n = str.Tlength() - str.length;num = num - parseInt(n/2);return this.substr(this.length-num);}

//字符串包含
String.prototype.GetCount = function(str,mode){return eval("this.match(/("+str+")/g"+(mode?"i":"")+").length");}

//字符串去除兩端空字符
String.prototype.Trim=function(){return this.replace(/(^/s*)(/s*$)/g,"");}
String.prototype.Ltrim = function(){return this.replace(/(^/s*)/g, "");}
String.prototype.Rtrim = function(){return this.replace(/(/s*$)/g, "");}

document.write("'aa啦啦aa'.Tlength() = " + "aa啦啦aa".Tlength());
document.write("<br>");
document.write("'aabbcc'.Tlength() = " + "aabbcc".Tlength());
document.write("<br>");
document.write("'aa啦啦aa'.left(4) = " + "aa啦啦aa".left(4));
document.write("<br>");
document.write("'aa啦啦aa'.left(4,true) = " + "aa啦啦aa".left(4,true));
document.write("<br>");
document.write("'aa啦啦aa'.right(4) = " + "aa啦啦aa".right(4));
document.write("<br>");
document.write("'aa啦啦aa'.right(4,true) = " + "aa啦啦aa".right(4,true));
document.write("<br>");
document.write("'abAcae'.GetCount('a') = " + "abAcae".GetCount("a"));
document.write("<br>");
document.write("'abAcae'.GetCount('a',true) = " + "abAcae".GetCount("a",true));
document.write("<br>");
document.write("'  abc  de    '.Ltrim() = " + "  abc  de    ".Ltrim());
document.write("<br>");
document.write("'  abc  de    '.Rtrim() = " + "  abc  de    ".Rtrim());
document.write("<br>");
document.write("'  abc  de    '.Trim() = " + "  abc  de    ".Trim());
</script>


再來幾個函數,getCookie(),getQuery(),DateDiff(),DateAdd(),b2s(),原+改


function getCookie(mainKey,subKey) {
 var reg = new RegEXP("(^ )"+mainKey+"=([^;]*)(;$)");
 var arr = document.cookie.match(reg);
 if (arguments.length == 2) {
  if (arr!=null)
   return key(subKey,arr[2]);
  else


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平塘县| 阿巴嘎旗| 安新县| 江门市| 扶绥县| 时尚| 平江县| 东乡县| 沁阳市| 山阳县| 休宁县| 大宁县| 武宣县| 林州市| 庆元县| 高雄市| 景洪市| 广汉市| 太谷县| 武胜县| 外汇| 三台县| 凤庆县| 古交市| 来凤县| 新竹县| 平安县| 长垣县| 东莞市| 荆州市| 和平县| 遵义市| 孝感市| 湘潭市| 内丘县| 贵阳市| 屏东市| 清流县| 湘潭县| 咸阳市| 宣化县|