1. 기본 JavaScript는 문자열 길이 요격을 구현합니다
코드 사본은 다음과 같습니다.
함수 컷스트 스트 (str, len) {
var 온도;
var iCount = 0;
var patrn =/[^/x00-/xff]/;
var strre = "";
for (var i = 0; i <str.length; i ++) {
if (iCount <len -1) {
temp = str.substr (i, 1);
if (patrn.exec (temp) == null) {
아이콘 = 아이콘 + 1
} 또 다른 {
아이콘 = 아이콘 + 2
}
strre += 온도
} 또 다른 {
부서지다
}
}
return strre + "..."
}
2. 도메인 이름 호스트를 얻기위한 기본 JavaScript
코드 사본은 다음과 같습니다.
함수 gethost (url) {
var host = "null";
if (typeof url == "undefined"|| null == url) {
url = window.location.href;
}
var regex = /^/w+/:///(......// ]* :/;
var match = url.match (regex);
if (typeof match! = "undefined"&& null! = match) {
호스트 = 일치 [1];
}
리턴 호스트;
}
3. 기본 JavaScript는 공간을 지 웁니다
코드 사본은 다음과 같습니다.
String.prototype.trim = function () {
var reextraspace = /^/s*(.*??)/s+$/;
recond.replace (Reextraspace, "$ 1")
}
4. 기본 JavaScript를 모두 교체하십시오
코드 사본은 다음과 같습니다.
String.prototype.replaceall = function (s1, s2) {
return this.replace (New Regexp (S1, "GM"), S2)
}
5. 기본 JavaScript가 HTML 태그를 빠져 나갑니다
코드 사본은 다음과 같습니다.
함수 htmlencode (텍스트) {
return text.replace (/&/g, '&'). 교체 (// "/g, '') .replace (/</g, '<'). 교체 (// g, '>')
}
6. 기본 JavaScript는 HTML 태그를 복원합니다
코드 사본은 다음과 같습니다.
함수 htmldecode (텍스트) {
return text.replace (/&/g, '&'). 교체 (// g, '/"') .replace(/</g, '<'). 교체 (// g, '>')
}
7. 기본 JavaScript 시간 및 날짜 형식을 변환하십시오
코드 사본은 다음과 같습니다.
date.prototype.format = function (formatstr) {
var str = Formatstr;
var week = [ 'day', 'one', 'two', 'three', 'four', 'five', 'six'];
str = str.replace (/yyyy | yyyy/, this.getlyear ());
str = str.replace (/yy | yy/, (this.getyear () % 100)> 9?
str = str.replace (/mm/, (this.getmonth () + 1)> 9?
str = str.replace (/m/g, (this.getmonth () + 1));
str = str.replace (/w | w/g, Week [this.getDay ()];
str = str.replace (/dd | dd/, this.getDate ()> 9? this.getDate (). toString () : '0' + this.getDate ());
str = str.replace (/d | d/g, this.getDate ());
str = str.replace (/hh | hh/, this.gethours ()> 9? this.gethours (). toString () : '0' + this.gethours ());
str = str.replace (/h | h/g, this.gethours ());
str = str.replace (/mm/, this.getminutes ()> 9? this.getminutes (). toString () : '0' + this.getMinutes ());
str = str.replace (/m/g, this.getminutes ());
str = str.replace (/ss | ss/, this.getSeconds ()> 9? this.getSeconds (). toString () : '0' + this.getSeconds ());
str = str.replace (/s | s/g, this.getSeconds ());
Return Str
}
8. 기본 JavaScript가 숫자 유형인지 여부를 결정합니다.
코드 사본은 다음과 같습니다.
기능 isdigit (value) {
var patrn = /^[0-9]*$ /;
if (patrn.exec (value) == null || value == "") {
거짓을 반환하십시오
} 또 다른 {
진실을 반환하십시오
}
}
9. 기본 JavaScript에서 쿠키 값을 설정하십시오
코드 사본은 다음과 같습니다.
함수 setCookie (이름, 가치, 시간) {
var d = 새로운 날짜 ();
var 오프셋 = 8;
var utc = d.gettime () + (d.gettimezoneoffset () * 60000);
var nd = utc + (3600000 * 오프셋);
var exp = 새로운 날짜 (nd);
exp.settime (exp.gettime () + 시간 * 60 * 60 * 1000);
document.
}
10. 기본 JavaScript는 쿠키 가치를 얻습니다
코드 사본은 다음과 같습니다.
함수 getCookie (이름) {
var arr = document.cookie.match (새 regexp ( "(^|)" + name + "= ([^;]*) (; | $)");
if (arr! = null) 반환 unesce (arr [2]);
널 리턴
}