1. JavaScript الأصلي ينفذ اعتراض طول السلسلة
نسخة الكود كما يلي:
وظيفة cutstr (str ، len) {
var temp ؛
var icount = 0 ؛
var gatrn =/[^/x00-/xff]/؛
var strre = "" ؛
لـ (var i = 0 ؛ i <str.length ؛ i ++) {
if (icount <len - 1) {
temp = str.substr (i ، 1) ؛
if (gatrn.exec (temp) == null) {
أيقونة = أيقونة + 1
} آخر {
أيقونة = أيقونة + 2
}
Strre += Temp
} آخر {
استراحة
}
}
إرجاع Strre + "..."
}
2. JavaScript الأصلي للحصول على مضيف اسم المجال
نسخة الكود كما يلي:
وظيفة gethost (url) {
var host = "null" ؛
if (typeof url == "undefined" || null == url) {
url = window.location.href ؛
}
var regex = /^/w+/://// (Budap ^///201*).*// ؛
var match = url.match (regex) ؛
if (typeof match! = "undefined" && null! = match) {
مضيف = تطابق [1] ؛
}
عودة المضيف
}
3. JavaScript الأصلي يمسح المساحات
نسخة الكود كما يلي:
string.prototype.trim = function () {
var reextraspace = /^/s*(.*؟)/s+ $/ ؛
إرجاع this.replace (reextraspace ، "$ 1")
}
4. جافا سكريبت الأصلي يحل محل الجميع
نسخة الكود كما يلي:
string.prototype.replaceall = function (S1 ، S2) {
إرجاع this.replace (regexp جديد (S1 ، "GM") ، S2)
}
5. JavaScript الأصلي يهرب علامات HTML
نسخة الكود كما يلي:
وظيفة htmlencode (نص) {
إرجاع text.replace (/&/g ، '&'). استبدال (// "/g ، '') .replace (/</g ، '<'). استبدال (// g ، '>')
}
6. JavaScript الأصلي يستعيد علامات HTML
نسخة الكود كما يلي:
دالة htmldecode (نص) {
إرجاع text.replace (/&/g ، '&'). استبدال (// g ، '/"').
}
7. تحويل تنسيق وقت JavaScript الأصلي
نسخة الكود كما يلي:
date.prototype.format = function (formatstr) {
var str = formatstr ؛
var week = ['Day' ، 'One' ، 'اثنين' ، 'Three' ، 'Four' ، 'Five' ، 'Six'] ؛
str = str.replace (/yyyy | yyyy/، this.getlyear ()) ؛
str = str.replace (/yy | yy/، (this.getyear () ٪ 100)> 9؟ (this.getyear () ٪ 100) .ToString (): '0' + (this.getyear () ٪ 100)) ؛
str = str.replace (/mm/، (this.getMonth () + 1)> 9؟ (this.getMonth () + 1) .ToString (): '0' + (this.getMonth () + 1)) ؛
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 ()) ؛
إرجاع شارع
}
8. يحدد JavaScript الأصلي ما إذا كان نوعًا رقميًا
نسخة الكود كما يلي:
وظيفة isDigit (القيمة) {
var gatrn = /^[0-9]*$ /؛
if (gatrn.exec (value) == null || value == "") {
العودة كاذبة
} آخر {
العودة الحقيقية
}
}
9. تعيين قيمة ملفات تعريف الارتباط في JavaScript الأصلي
نسخة الكود كما يلي:
وظيفة setCoOkie (الاسم ، القيمة ، الساعات) {
var d = new Date () ؛
var offset = 8 ؛
var utc = d.getTime () + (D.GetTimeZoneOffset () * 60000) ؛
var nd = utc + (3600000 * ارhfset) ؛
var exp = تاريخ جديد (nd) ؛
exp.Settime (exp.getTime () + ساعات * 60 * 60 * 1000) ؛
document.cookie = name + "=" + Escape (value) + "؛ path =/؛ expires =" + exp.togmtstring () + "؛ domain = 360doc.com ؛"
}
10. جافا سكريبت الأصلي يحصل على قيمة ملفات تعريف الارتباط
نسخة الكود كما يلي:
وظيفة getCookie (الاسم) {
var arr = document.cookie.match (جديد regexp ("(^|)" + name + "= ([^؛]*) (؛ | $)")) ؛
إذا (arr! = null) إرجاع unescape (arr [2]) ؛
العودة لاغية
}