函數appendscript(src, text, reload, charset) {
var id = hash(src text);
if(!reload && in_array(id, evalscripts)) return;
if(reload && $(id)) {
$(id).parentNode.removeChild($(id));
}
evalscripts.push(id);
var scriptNode = document.createElement("script");
scriptNode.type = "text/javascript";
scriptNode.id = idNode.type = "text/javascript";
scriptNode.id = idNode. 嘗試{
if(src) {
= false;
scriptNode.onload = function () {
scriptNode. = true;
JSLOADED[src] = 1;
};
|| scriptNode.readyState = = '完整') && !scriptNode. {
scriptNode. = true;
JSLOADED[src } 🎜> } else if(text){
scriptNode .text = text;
}
document.getElementsByTagName('head')[0].appendChild(scriptNode);
} catch(e) {}
}
18 、複製JavaScript返回按ID搜尋的元素物件
複製程式碼Event obj.attachEvent('on' evt,fn);
}
}
23、原生JavaScript遊標停在文字的後面,文字方塊取得焦點時呼叫
function focusLast(){
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart('character',). length);
r.collapse(true);
r.select();
}
24、原生JavaScript檢驗URL連結是否有效
function getUrlState(URL){
var xmlhttp = new ActiveX ;
xmlhttp.Open("GET",URL, false);
try{
xmlhttp.Send();
}catch(e){
}finally result = xmlhttp.responseText;
if(result){
if(xmlhttp.Status==200){
return(false);
}
}else{
return(false);
}
Ofido
>格式化🎜>樣式
複製程式碼
程式碼如下:
s = s.replace(/([^s])}([^n]*)/g, "$1n}n$2");
s = s.replace(/([^s]);([^s}])/g, "$1;nt$2");
return s;
}
26.原生JavaScript壓縮CSS樣式程式碼
複製程式碼
程式碼如下:
s = s.replace(//*(.|n)*?*//g, ""); //刪除註解
s = s.replace(/s* ([{}:;,])s*/g, "$1");
s = s.replace(/,[s.#d]*{/g, "{"); //容錯處理
s = s.replace(/;s*;/g, ";"); //清除連續分號
s = s.match(/^s*(S (s S )*)s *$/); //去掉首尾空白
return (s == null) ? "" : s[1];
}
27、原生JavaScript取得目前路徑
複製程式碼
程式碼如下:var currentPageUrl = "";
if (type = .this.href == "undefined") {
currentPageUrl = document.location.toString().toLowerCase();
}
else {
currentPageUrl = .else {
);
}
28、原生JavaScriptIP轉成整數
function _ip2int(ip){
var num = 0;
ip = ip.split(".");
ip = ip.split(".");
ip = ip.split(".");
num = Number(ip60]) * * 256 Number(ip[1]) * 256 * 256 Number(ip[2]) * 256 Number(ip[3]);
num = num >>> 0;
return num;
}
29、原生JavaScript整型解析為IP位址
程式碼如下:
function _int2iP(num){
var str;
var tt = new Array();
tt[0] = (num >>> 24); > tt[1] = ((num >> 24) >>> 0;
tt[2] = (num >> 24; tt[3] = (num >> 24; str = String(tt[0]) "." String(tt[1]) "." String(tt[2]) "." String(tt[ 3]); return str;}
30、原生JavaScript實作checkbox全選與全不選
程式碼如下:
程式碼如下:function checkAll() {
var selectall = document.getElementById("selectall");
var allbox = document.getElementsByName("allbox");
eck ( > for (var i = 0; i allbox[i].checked = true;
}
} else {
¢ allbox[i].checked = false;
}
}
}
複製程式碼
複製程式碼
程式碼如下:
function isMobile(){
if (typeof this._isMobile === 'boolean'){
return this._isMobile;
= this.getScreenWidth();
var fixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixview.
=== "new");
if(!fixViewPortsExperiment){
if(!this.isAppleMobileDevice()){
screenWidth = screenWidth/window.devicePixeldio; isMobileScreenSize = screenWidth var isMobileUserAgent = false;
複製程式碼
程式碼如下:
複製碼
程式碼如下:
複製程式碼
程式碼如下:
複製代碼
程式碼如下:
複製程式碼
程式碼如下:
程式碼如下:
function isNewChromeOnAndroid(){
if(this.isAndroidMobileDevice()){
var userAgent = navigator.userAgent.toLowerCase();
)){
var parts = userAgent.split('chrome/');
var fullVersionString = parts[1].split(" ")[0];
var versionString = fullVersionString.split('.')[0]
if(version >= 27){
return true;
}
🎜>37、原生JavaScript判斷是否打開視窗複製程式碼
程式碼如下:
function isViewportOpen() {
return !!document.getElementById('wixMobileViewport');
}
38、原生JavaScriptScriptScript. >
function getInitZoom(){
if(!this._inZZi){ 🎜> var screenWidth = Math.min(screen.height, screen.width);
if(this.isAndroidMobileDevice() && ! ixelRatio;
}
this._initZoom = screenWidth /document.body.offsetWidth;
}
return this._initZoom;<.>
複製程式碼
程式碼如下:
function getZoom(){ if(this.isAndroidMobileDevice() &width);
if(this.isAndroidMobileDevice() &width);
if(this.isAndroidMobileDevice() &width);
if(this.isAndroidMobileDevice() &width);
!this.isNewChromeOnAndroid()){
screenWidth = screenWidth/window.devicePixelRatio;
}
var FixViewPortsExperiment =||sExperimentl. 🎜> var FixViewPortsExperimentRunning = FixViewPortsExperiment && (FixViewPortsExperiment === "New" || FixViewPortsExperiment === "new");
if(FixViewPortsExperimentRunning){
return screenWidth / window. th / document .body.offsetWidth;
}
}
40、原生JavaScript取得行動裝置螢幕寬度