📄 common.js
字号:
/*
Copyright 2006 Christian Gross http://www.devspace.com
From the book Ajax Patterns and Best Practices
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function getSelectedValue( element) { var select = el( "age"); //obj.age = select.options[ select.selectedIndex].value;}function setSelectedValue( element, value) { for( var c1 = 0; c1 < element.options.length; c1 ++) { if( element.options[ c1].value == value) { element.selectedIndex = c1; return; } }}function convertToSource(obj) {
if ( navigator.appName == 'Netscape' ) {
return( obj.toSource() );
}
// ECMAScript and IE 5.00 do not support "toSource()", so lets try
// implementing its functionality here
var sourceString = "";
if (typeof(obj) == "undefined")
{
sourceString = "undefined";
}
else if (obj == null)
{
sourceString = "null";
}
else if (typeof(obj) == "boolean" || typeof(obj) == "number" || typeof(obj) == "function")
{
sourceString = obj;
}
else if (typeof(obj) == "string")
{
sourceString = "'" + obj.replace(/([\\'"])/g, "\\$1") + "'";
}
else if (typeof(obj) == "object")
{
if (obj.constructor == Boolean)
{
sourceString = "new Boolean(" + obj.valueOf() + ")";
}
else if (obj.constructor == Number)
{
sourceString = "new Number(" + obj.valueOf() + ")";
}
else if (obj.constructor == String)
{
sourceString = "new String(" + convertToSource(obj.toString()) + ")";
}
else if (obj.constructor == Date)
{
sourceString = "new Date(" + obj.valueOf() + ")";
}
else if (obj.constructor == Array)
{
sourceString = "[";
for (var i=0; i<obj.length; i++)
sourceString += convertToSource(obj[i]) + ",";
if (i>0)
sourceString = sourceString.substring(0, sourceString.length-1);
sourceString += "]";
}
else if (obj.constructor == RegExp)
{
sourceString = obj.toString().replace(/\\/g, "\\\\");
}
else if (obj.constructor == Object)
{
var sourceString = "{"
for (var key in obj)
sourceString = sourceString + "" + key + ":" + convertToSource(obj[key]) + ","
if (sourceString.length > 1)
sourceString = sourceString.substring(0, sourceString.length-1);
sourceString += "}";
}
}
else
{
sourceString = "convertToSource encountered unexpected object type: " + typeof(obj);
}
return sourceString;
} // http://www.dustindiaz.com/top-ten-javascript/// // http://dean.edwards.name/my/cssQuery/// function el( id) { return document.getElementById( id);}function elParseElement( element, findid) { if( element.nodeType == 1) { if( element.id == findid) { return element; } for( var i = 0; i < element.childNodes.length; i ++) { var retval = elParseElement( element.childNodes[ i], findid); if( retval) { return retval; } } } return null;}function localel( parent, findid) { return elParseElement( document.getElementById( parent), findid);}function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; } else { elm['on' + evType] = fn; }}function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } }}//addEvent(window,'load',func1,false);//addEvent(window,'load',func2,false);//addEvent(window,'load',func3,false);// function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements;}function switchMenu(obj) { var el = document.getElementById(obj); if ( el.style.display != 'none' ) { el.style.display = 'none'; } else { el.style.display = ''; } }function insertAfter(parent, node, referenceNode) { parent.insertBefore(node, referenceNode.nextSibling);}Array.prototype.inArray = function (value) { var i; for (i=0; i < this.length; i++) { if (this[i] === value) { return true; } } return false;}function getCookie( name ) { var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ";", len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) );} function setCookie( name, value, expires, path, domain, secure ) { var today = new Date(); today.setTime( today.getTime() ); if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date( today.getTime() + (expires) ); document.cookie = name+"="+escape( value ) + ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString() ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );} function deleteCookie( name, path, domain ) { if ( getCookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=\"" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";}function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements;} // Sample Usage:/*var obj1 = document.getElementById('element1');var obj2 = document.getElementById('element2');function alertElements() { var i; var elements = $('a','b','c',obj1,obj2,'d','e'); for ( i=0;i<elements.length;i++ ) { alert(elements[i].id); }}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -