/*** 刪除首尾空格 ***/
String.prototype.Trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
/*** 統(tǒng)計指定字符出現(xiàn)的次數(shù) ***/
String.prototype.Occurs = function(ch) {
// var re = eval("/[^"+ch+"]/g");
// return this.replace(re, "").length;
return this.split(ch).length-1;
}
/*** 檢查是否由數(shù)字組成 ***/
String.prototype.isDigit = function() {
var s = this.Trim();
return (s.replace(/\d/g, "").length == 0);
}
/*** 檢查是否由數(shù)字字母和下劃線組成 ***/
String.prototype.isAlpha = function() {
return (this.replace(/\w/g, "").length == 0);
}
/*** 檢查是否為數(shù) ***/
String.prototype.isNumber = function() {
var s = this.Trim();
return (s.search(/^[+-]?[0-9.]*$/) >= 0);
}
/*** 返回字節(jié)數(shù) ***/
String.prototype.lenb = function() {
return this.replace(/[^\x00-\xff]/g,"**").length;
}
/*** 檢查是否包含漢字 ***/
String.prototype.isInChinese = function() {
return (this.length != this.replace(/[^\x00-\xff]/g,"**").length);
}
/*** 檢查是否有列表中的字符字符 ***/
String.prototype.isInList = function(list) {
var re = eval("/["+list+"]/");
return re.test(this);
}
/*** 簡單的email檢查 ***/
String.prototype.isEmail = function() {
var strr;
var mail = this;
var re = /(\w+@\w+\.\w+)(\.\w*)(\.\w*)/i;
re.exec(mail);
if(RegExp.!="" && RegExp.!="." && RegExp.!=".")
strr = RegExp.+RegExp.+RegExp.;
else
if(RegExp.!="" && RegExp.!=".")
strr = RegExp.+RegExp.;
else
strr = RegExp.;
return (strr==mail);
}
/*** 簡單的日期檢查,成功返回日期對象 ***/
String.prototype.isDate = function() {
var p;
var re1 = /(\d)[年./-](\d)[月./-](\d)[日]?$/;
var re2 = /(\d)[月./-](\d)[日./-](\d)[年]?$/;
var re3 = /(\d)[月./-](\d)[日./-](\d)[年]?$/;
if(re1.test(this)) {
p = re1.exec(this);
return new Date(p[1],p[2],p[3]);
}
if(re2.test(this)) {
p = re2.exec(this);
return new Date(p[3],p[1],p[2]);
}
if(re3.test(this)) {
p = re3.exec(this);
return new Date(p[3],p[1],p[2]);
}
return false;
}
//驗證手機號
function isMobileNum(num){
var reg = /^((13[0-9]{1})|(15[0, 8, 0]{1})){1}\d{8}$/;
if (reg.test(num)){
return true;
}else{
return false;
}
}
//簡單驗證是否包含特定字符
var num = "023456789";
if(num.indexOf("23") != -1)
{
alert('包含');
}
//實現(xiàn)頁面的自動跳轉(zhuǎn) IE、Firefox都適用
<script type="text/javascript">
location.href="index.action";
</script>
//控件是否存在
<script type="text/javascript"> var a= document.getElementById("dd");
if(a==null)
{
//ddd
}
</script>
//獲取頁面的URL
//如果獲取“當(dāng)前”域名,當(dāng)頁面A包含在頁面B中時,在A中使用此方法返回的是A的地址
host = window.location.host;
url=document.domain;
url = window.location.href; //獲取瀏覽器地址欄中url地址
top.location
thisURL = document.URL;
//http://localhost:81/Test/1.htm?Did=123
thisHREF = document.location.href;
//http://localhost:81/Test/1.htm?Did=123
thisSLoc = self.location.href;
//http://localhost:81/Test/1.htm?Did=123
thisDLoc = document.location;
//http://localhost:81/Test/1.htm?Did=123
thisTLoc = top.location.href;
//http://localhost:81/Test/1.htm?Did=123
thisPLoc = parent.document.location;
//http://localhost:81/Test/1.htm?Did=123
thisTHost = top.location.hostname;
// localhost
thisHost = location.hostname;
// localhost
thisU1 = window.location.protocol;
// http:
thisU2 = window.location.host;
// localhost:81
thisU3 = window.location.pathname;
// /Test/1.htm
GOOGLE 日歷API地址
http://code.google.com/intl/zh-CN/apis/calendar/