{"id":154,"date":"2010-09-30T11:05:32","date_gmt":"2010-09-30T11:05:32","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=154"},"modified":"2010-09-30T11:05:32","modified_gmt":"2010-09-30T11:05:32","slug":"js-%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/09\/30\/js-%e9%aa%8c%e8%af%81\/","title":{"rendered":"JS \u9a8c\u8bc1"},"content":{"rendered":"<p>\u5229\u7528Javascript\u4e2d\u6bcf\u4e2a\u5bf9\u8c61(Object)\u7684prototype\u5c5e\u6027\u6211\u4eec\u53ef\u4ee5\u4e3aJavascript\u4e2d\u7684\u5185\u7f6e\u5bf9\u8c61\u6dfb\u52a0\u6211\u4eec\u81ea\u5df1\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\u3002\u53ef\u76f4\u63a5\u8c03\u7528!\/\/\u81ea\u5b9a\u4e49\u6269\u5c55\u65b9\u6cd5\uff0c\u4f9b\u5916\u90e8\u8c03\u7528<\/p>\n<pre lang=\"javascript\">\r\nString.prototype.isNull = testNull;\/\/\u5224\u65ad\u662f\u5426\u4e3a\u7a7a\r\nString.prototype.number = testNumber;\/\/\u5224\u65ad\u6570\u5b57,\u53ea\u80fd\u4e3a\u6574\u6570\r\nString.prototype.doubleNumber = testDoubleNumber;\/\/\u5224\u65ad\u6570\u5b57,\u53ef\u4ee5\u4e3a\u5c0f\u6570\r\nString.prototype.zip = testZip;\/\/\u5224\u65ad\u90ae\u653f\u7f16\u7801\u683c\u5f0f\r\nString.prototype.phone = testPhoneNumber;\/\/\u5224\u65ad\u8054\u7cfb\u7535\u8bdd\u3001\u4f20\u771f\u683c\u5f0f\r\nString.prototype.email = testEmail;\/\/\u5224\u65ad\u7535\u5b50\u90ae\u7bb1\u683c\u5f0f\r\n\/\/\u5224\u65ad\u662f\u5426\u4e3a\u7a7a,\u4e3a\u7a7a\u5219\u8fd4\u56detrue\r\nfunction testNull(){\r\nif(this.replace(\/(^\\s*)|(\\s*$)\/g, '').length<=0)\r\n{\/\/\u4e3a\u7a7a\r\n   return true;\r\n}\r\nelse{\/\/\u4e0d\u4e3a\u7a7a\r\n   return false;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u662f\u5426\u4e3a\u6570\u5b57,\u662f\u6570\u5b57\u5219\u8fd4\u56detrue\r\nfunction testNumber()\r\n{\r\nif(!this.isNull()){\r\n   for(i=0;i<this.length;i++) \r\n   { \r\n    if(this.charAt(i)<\"0\"||this.charAt(i)>\"9\")\r\n    {\r\n     return false;\r\n    }\r\n   }\r\n   return true;\r\n}\r\nelse\r\n{\r\n   return true;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u90ae\u653f\u7f16\u7801\u683c\u5f0f\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testZip()\r\n{\r\nif(!this.isNull()){\r\n   if(this.length!=6)\r\n   {\r\n    return false;\r\n   }\r\n   else\r\n   {\r\n    var rexTel=\/^[0-9]+$\/;\r\n    if(!rexTel.test(this))\r\n    {\r\n     return false;\r\n    }\r\n   }\r\n}\r\nreturn true;\r\n}\r\n\/\/\u5224\u65ad\u8054\u7cfb\u7535\u8bdd\u3001\u4f20\u771f\u683c\u5f0f\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testPhoneNumber()\r\n{ \r\nif(!this.isNull()){\r\n   var reg=\/(^[0-9]{3,4}\\-[0-9]{7,8}\\-[0-9]{3,4}$)|(^[0-9]{3,4}\\-[0-9]{7,8}$)|(^[0-9]{7,8}\\-[0-9]{3,4}$)|(^[0-9]{7,15}$)\/;\r\n   if(!reg.test(this))\r\n   {\r\n    return false;\r\n   }\r\n   return true;\r\n}\r\nelse\r\n{\r\n   return true;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u7535\u5b50\u90ae\u7bb1\u683c\u5f0f\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testEmail()\r\n{\r\nif(!this.isNull()){\r\n   if(this.search(\/^([-_A-Za-z0-9\\.]+)@([_A-Za-z0-9]+\\.)+[A-Za-z0-9]{2,3}$\/)!=-1)\r\n   {\r\n    return true;\r\n   }\r\n   else\r\n   {\r\n    return false;\r\n   }\r\n}\r\nelse\r\n{\r\n   return true;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u662f\u5426\u662f\u6570\u5b57\uff0c\u53ef\u4ee5\u4e3a\u5c0f\u6570\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testDoubleNumber()\r\n{\r\nvar pointCount=0;\r\nfor(var i=0;i<this.length;i++){\r\n   if((this.charAt(i)<'0'||this.charAt(i)>'9')&&this.charAt(i)!='.'){\r\n    return false;\r\n   }\r\n   else{\r\n    if(this.charAt(i)=='.')pointCount++;\r\n   }\r\n}\r\nif(pointCount>1){\r\n   return false;\r\n}else if(pointCount==1&&this.trim().length==1){\r\n   return false;\r\n}\r\nreturn true;\r\n}\r\n \r\n\/\/\u81ea\u5b9a\u4e49\u6269\u5c55\u65b9\u6cd5\uff0c\u4f9b\u5916\u90e8\u8c03\u7528\r\nString.prototype.isNull = testNull;\/\/\u5224\u65ad\u662f\u5426\u4e3a\u7a7a\r\nString.prototype.number = testNumber;\/\/\u5224\u65ad\u6570\u5b57,\u53ea\u80fd\u4e3a\u6574\u6570\r\nString.prototype.doubleNumber = testDoubleNumber;\/\/\u5224\u65ad\u6570\u5b57,\u53ef\u4ee5\u4e3a\u5c0f\u6570\r\nString.prototype.zip = testZip;\/\/\u5224\u65ad\u90ae\u653f\u7f16\u7801\u683c\u5f0f\r\nString.prototype.phone = testPhoneNumber;\/\/\u5224\u65ad\u8054\u7cfb\u7535\u8bdd\u3001\u4f20\u771f\u683c\u5f0f\r\nString.prototype.email = testEmail;\/\/\u5224\u65ad\u7535\u5b50\u90ae\u7bb1\u683c\u5f0f\r\n\/\/\u5224\u65ad\u662f\u5426\u4e3a\u7a7a,\u4e3a\u7a7a\u5219\u8fd4\u56detrue\r\nfunction testNull(){\r\nif(this.replace(\/(^\\s*)|(\\s*$)\/g, '').length<=0)\r\n{\/\/\u4e3a\u7a7a\r\n   return true;\r\n}\r\nelse{\/\/\u4e0d\u4e3a\u7a7a\r\n   return false;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u662f\u5426\u4e3a\u6570\u5b57,\u662f\u6570\u5b57\u5219\u8fd4\u56detrue\r\nfunction testNumber()\r\n{\r\nif(!this.isNull()){\r\n   for(i=0;i<this.length;i++) \r\n   { \r\n    if(this.charAt(i)<\"0\"||this.charAt(i)>\"9\")\r\n    {\r\n     return false;\r\n    }\r\n   }\r\n   return true;\r\n}\r\nelse\r\n{\r\n   return true;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u90ae\u653f\u7f16\u7801\u683c\u5f0f\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testZip()\r\n{\r\nif(!this.isNull()){\r\n   if(this.length!=6)\r\n   {\r\n    return false;\r\n   }\r\n   else\r\n   {\r\n    var rexTel=\/^[0-9]+$\/;\r\n    if(!rexTel.test(this))\r\n    {\r\n     return false;\r\n    }\r\n   }\r\n}\r\nreturn true;\r\n}\r\n\/\/\u5224\u65ad\u8054\u7cfb\u7535\u8bdd\u3001\u4f20\u771f\u683c\u5f0f\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testPhoneNumber()\r\n{ \r\nif(!this.isNull()){\r\n   var reg=\/(^[0-9]{3,4}\\-[0-9]{7,8}\\-[0-9]{3,4}$)|(^[0-9]{3,4}\\-[0-9]{7,8}$)|(^[0-9]{7,8}\\-[0-9]{3,4}$)|(^[0-9]{7,15}$)\/;\r\n   if(!reg.test(this))\r\n   {\r\n    return false;\r\n   }\r\n   return true;\r\n}\r\nelse\r\n{\r\n   return true;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u7535\u5b50\u90ae\u7bb1\u683c\u5f0f\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testEmail()\r\n{\r\nif(!this.isNull()){\r\n   if(this.search(\/^([-_A-Za-z0-9\\.]+)@([_A-Za-z0-9]+\\.)+[A-Za-z0-9]{2,3}$\/)!=-1)\r\n   {\r\n    return true;\r\n   }\r\n   else\r\n   {\r\n    return false;\r\n   }\r\n}\r\nelse\r\n{\r\n   return true;\r\n}\r\n}\r\n\/\/\u5224\u65ad\u662f\u5426\u662f\u6570\u5b57\uff0c\u53ef\u4ee5\u4e3a\u5c0f\u6570\uff0c\u683c\u5f0f\u6b63\u786e\u8fd4\u56detrue\r\nfunction testDoubleNumber()\r\n{\r\nvar pointCount=0;\r\nfor(var i=0;i<this.length;i++){\r\n   if((this.charAt(i)<'0'||this.charAt(i)>'9')&&this.charAt(i)!='.'){\r\n    return false;\r\n   }\r\n   else{\r\n    if(this.charAt(i)=='.')pointCount++;\r\n   }\r\n}\r\nif(pointCount>1){\r\n   return false;\r\n}else if(pointCount==1&&this.trim().length==1){\r\n   return false;\r\n}\r\nreturn true;\r\n}\r\n \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528Javascript\u4e2d\u6bcf\u4e2a\u5bf9\u8c61(Object)\u7684prototype\u5c5e\u6027\u6211\u4eec\u53ef\u4ee5\u4e3aJavascript\u4e2d\u7684\u5185 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-javascript"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}