1. Javascript nativo implementa o comprimento da string intercepto
A cópia do código é a seguinte:
função cutstr (str, len) {
var temp;
var iCount = 0;
var patn =/[^/x00-/xff]/;
var strre = "";
for (var i = 0; i <str.Length; i ++) {
if (iCount <len - 1) {
temp = str.substr (i, 1);
if (patn.exec (temp) == null) {
ícone = ícone + 1
} outro {
ícone = ícone + 2
}
strre += temp
} outro {
quebrar
}
}
Retornar Strre + "..."
}
2. JavaScript nativo para obter o host de nome de domínio
A cópia do código é a seguinte:
função gethost (url) {
var host = "null";
if (typeof url == "indefinido" || null == url) {
url = window.location.href;
}
var regex = /^/w+/:///////i////4;
var correspondente = url.match (regex);
if (typeof match! = "indefinido" && null! = Match) {
host = correspondência [1];
}
host de retorno;
}
3. JavaScript nativo limpa os espaços
A cópia do código é a seguinte:
String.prototype.trim = function () {
var reextraSpace = /^/s*(.*?)/s+$/;
Retorne this.Replace (ReextraSpace, "$ 1")
}
4. Javascript nativo substitua todos
A cópia do código é a seguinte:
String.prototype.Replaceall = function (S1, S2) {
Retorne this.Replace (novo regexp (S1, "GM"), S2)
}
5. JavaScript nativo escapa de tags html
A cópia do código é a seguinte:
função htmlencode (text) {
Return text.Replace (///g, '&'). Substitua (// "/g, '') .Reparplace (/</g, '<'). Substitua (// g, '>')
}
6. JavaScript nativo restaura tags html
A cópia do código é a seguinte:
função htmldecode (text) {
Return text.Replace (///g, '&'). Substitua (// g, '/"'ropplace(/</g,' <'). Substitua (// g,'> ')
}
7. Converta o formato nativo de tempo e data do JavaScript
A cópia do código é a seguinte:
Date.prototype.format = function (formatStr) {
var str = formatStr;
var semana = ['dia', 'um', 'dois', 'três', 'quatro', 'cinco', 'seis'];
str = str.place (/yyyy | aaaa/, this.getlyear ());
str = str.place (/yy | yy/, (this.getyear () % 100)> 9? (this.getyear () % 100) .toString (): '0' + (this.getyear () % 100));
str = str.place (/mm/, (this.getMonth () + 1)> 9? (this.getMonth () + 1) .ToString (): '0' + (this.getMonth () + 1));
str = str.place (/m/g, (this.getMonth () + 1));
str = str.place (/w | w/g, semana [this.getday ()]);
str = str.place (/dd | dd/, this.getDate ()> 9? this.getDate (). tostring (): '0' + this.getDate ());
str = str.place (/d | d/g, this.getDate ());
str = str.place (/hh | hh/, this.gethours ()> 9? this.gethours (). tostring (): '0' + this.gethours ());
str = str.place (/h | h/g, this.gethours ());
str = str.place (/mm/, this.getminutes ()> 9? this.getminutes (). tostring (): '0' + this.getminutes ());
str = str.place (/m/g, this.getminutes ());
str = str.place (/ss | ss/, this.getSeconds ()> 9? this.getSeconds (). ToString (): '0' + this.getSeconds ());
str = str.place (/s | s/g, this.getSeconds ());
retornar str
}
8. JavaScript nativo determina se é um tipo numérico
A cópia do código é a seguinte:
função isdigit (value) {
var patn = /^[0-9]*$ /;
if (patn.exec (valor) == null || value == "") {
retornar falso
} outro {
retornar verdadeiro
}
}
9. Defina o valor do cookie em JavaScript nativo
A cópia do código é a seguinte:
função setcookie (nome, valor, horas) {
var d = new Date ();
var offset = 8;
var utc = d.getTime () + (D.GetTimeZoneOffSet () * 60000);
var nd = utc + (3600000 * deslocamento);
var exp = nova data (nd);
Exp.setTime (exp.getTime () + horas * 60 * 60 * 1000);
document.cookie = nome + "=" + escape (value) + "; path =/; expires =" + exp.togmtString () + "; domain = 360doc.com;"
}
10. JavaScript nativo recebe o valor do cookie
A cópia do código é a seguinte:
função getcookie (nome) {
var arr = document.cookie.match (novo regexp ("(^|)" + nome + "= ([^;]*) (; | $)"));
if (arr! = null) retorna unescape (arr [2]);
retornar nulo
}