Jamson 发表于 2013-1-23 02:44:25

JavaScript中函数调用的一种扩展方法

JavaScript中函数调用的一种扩展方法:

check1.js:String.prototype.email = testEmail;//判断电子邮箱格式,扩展方法//------------------------------判断电子邮箱格式------------------------------function testEmail(){if(!this.isNull()){   if(this.search(/^([-_A-Za-z0-9\.]+)@(+\.)+{2,3}$/)!=-1){return true;}   else{alert("电子邮箱格式不正确!");         return false;}}else      {return true;      }}

check2.js:var email = document.getElementById("email");if(!email.value.email()){          //使用扩展方法alert("电子邮件格式不正确!");email.focus();return false;}
页: [1]
查看完整版本: JavaScript中函数调用的一种扩展方法