📄 base.js
字号:
/**
* 获得浏览器类型
*/
function Browser() {
var ua, s, i;
this.isIE = false; // Internet Explorer
this.isOP = false; // Opera
this.isNS = false; // Netscape
this.version = null;
ua = navigator.userAgent;
s = "Opera";
if ((i = ua.indexOf(s)) >= 0) {
this.isOP = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}
s = "Netscape6/";
if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}
s = "Gecko";
if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = 6.1;
return;
}
s = "MSIE";
if ((i = ua.indexOf(s))) {
this.isIE = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}
}
var browser = new Browser();
Object.extend(Event, {
addEvent : function (obj,eventName,eventFunc) {
if(obj.attachEvent) {
obj.attachEvent(eventName,eventFunc);
}else if(obj.addEventListener){
eventName = eventName.toString().replace(/on(.*)/i,'$1');
obj.addEventListener(eventName,eventFunc, false);
}
return eventFunc;
},
delEvent : function (obj,eventName,eventFunc) {
if(obj.detachEvent)
obj.detachEvent(eventName,eventFunc)
else if(obj.removeEventListener){
eventName = eventName.toString().replace(/on(.*)/i,'$1');
obj.removeEventListener(eventName,eventFunc, false);
}
return eventFunc;
},
getEvent : function () {
//获取Event
return window.event ? window.event : (function (o) {
do {
o = o.caller;
} while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0]));
return o.arguments[0];
})(this.getEvent);
}
}
);
/**
* 表单提交
*/
function formSubmit(forumId,button){
if (button){
button.disabled="true";
}
document.getElementById(forumId).submit();
}
/**
* 表单提交
*/
function submit(forumId){
document.getElementById(forumId).submit();
}
/**
* 表单清除
*/
function formReset(forumId){
document.getElementById(forumId).reset();
}
function isUndefined(variable) {
return typeof variable == 'undefined' ? true : false;
}
/**
* 获得事件操作对象
*/
function getEventSrcElement(event){
var obj;
if (browser.isIE)
obj = window.event.srcElement;
else
obj = event.currentTarget;
return obj;
}
/**
* 获得鼠标移向目标
*/
function getEventToElement(event){
var el;
if (browser.isIE)
el = window.event.toElement;
else if (event.relatedTarget != null)
el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
return el;
}
function getOffset(el) {
var width = el.offsetWidth;
var height = el.offsetHeight;
if (browser.isNS) {
height -= parseInt(el.style.borderTopWidth) * 2;
}
var top = 0;
var left = 0;
while(el != null){
top += el["offsetTop"];
left += el["offsetLeft"];
if (browser.isIE && el.offsetParent != null && el.offsetParent.tagName == "BODY"){
left += (el.offsetWidth - el.clientWidth)/2
}
el = el.offsetParent;
}
return {"top":top, "left":left, "width":width, "height":height};
};
/**
* 获得指定对象相对于浏览器的绝对定位
*/
function getAbsolutePosition(obj){
var top = obj.offsetTop;
var left = obj.offsetLeft;
var width=obj.offsetWidth;
var height=obj.offsetHeight;
while(obj.offsetParent){
obj = obj.offsetParent;
top += obj.offsetTop;
left += obj.offsetLeft;
}
return {"top":top, "left":left, "width":width, "height":height};
}
/**
* 获得指定对象相对于最近一个relative 或者 absolute 对象的相对位置
*/
function getRelativePosition(obj) {
var top=obj.offsetTop;
var left=obj.offsetLeft;
var width=obj.offsetWidth;
var height=obj.offsetHeight;
obj = obj.offsetParent
while (obj) {
var positionValue = Element.getStyle(obj, "position");
var overflowValue = Element.getStyle(obj, "overflow");
if ( positionValue == 'absolute' || positionValue == 'relative'
|| ( overflowValue != 'visible' && overflowValue != '' ) ){
break;
}
top += obj.offsetTop;
left += obj.offsetLeft;
obj = obj.offsetParent;
}
return {"top":top, "left":left, "width":width, "height": height};
}
/**
* 获得对象本身及外部 第一个tagName和className为指定值的对象
*/
function getContainerWith(node, tagName, className) {
while (node != null) {
if (node.tagName != null && node.tagName == tagName &&
Element.hasClassName(node, className))
return node;
node = node.parentNode;
}
return node;
}
/**
* 获得指定对象的子对象的offsetWidth
*/
function getChildNodeWidth(el){
var maxWidth = 0;
if(el.childNodes){
for(i=0;i<el.childNodes.length;i++){
if(el.childNodes[i].offsetWidth){
//return el.childNodes[i].offsetWidth;
var w = Element.getWidth(el.childNodes[i]);
if(w > maxWidth){
maxWidth = w;
}
}
}
if(maxWidth!=0) return maxWidth;
}
return Element.getWidth(el);
}
/**
* 获取浏览器的有些屏幕相对坐标及大小
*/
function getBrowserOffset(){
var top = 0;
var left = 0;
var width = 0;
var height = 0;
if (document.documentElement) {
top = document.documentElement.scrollTop;
left = document.documentElement.scrollLeft;
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
else if (document.body) {
top = document.body.scrollTop;
left = document.body.scrollLeft;
width = document.body.clientWidth;
height = document.body.clientHeight;
}
return {"top": top, "left": left, "width": width, "height": height};
}
/**
* 去字符串两端的空格
*/
function LTrim(s){
for(var i=0;i<s.length;i++)
if(s.charAt(i)!=' ')
return s.substring(i,s.length);
return "";
}
function RTrim(s){
for(var i=s.length-1;i>=0;i--)
if(s.charAt(i)!=' ')
return s.substring(0,i+1);
return "";
}
function Trim(s){
return RTrim(LTrim(s));
}
/**
* 检查输入的页码是否正确
*/
function checkPageNo(obj, minPage, maxPage, pageMethod){
try{
var no = parseInt(obj.value);
if(no >= minPage && no <= maxPage){
eval(pageMethod + "(" + no + ");");
return false;
}
}catch(e){
}
alert("请输入正确的页码");
return false;
}
/**
* 获得列表中,选中状态的checkBox数量
*/
function getCheckedNum(name){
var obj = document.getElementsByName(name);
if (obj){
var num = 0 ;
if(obj.length == undefined){
if(obj.checked==true){
num++;
}
}else{
for(var i=0; i<obj.length; i++){
if(obj[i].checked==true){
isChecked = true;
num++;
}
}
}
return num;
}
return 0;
}
/**
* 刷新验证码
*/
function newVerifyPic(contextPath,imgId){
document.getElementById(imgId).src=contextPath + "/checkNum" + '?new=' + Math.random() ;
}
/**
* 展开(缩起)指定对象
*/
function expandContent(expandId){
var obj = document.getElementById(expandId);
var display = Element.getStyle(obj, "display");
var curr = getEventSrcElement(Event.getEvent());
if(display != "none"){
display = "none";
if(curr.tagName == "IMG"){
curr.src = curr.src.replace("_yes", "_no");
}
}else{
display = "";
if(curr.tagName == "IMG"){
curr.src = curr.src.replace("_no", "_yes");
}
}
obj.style.display = display;
}
/*================================下拉菜单功能=====================================*/
/**当前激活的按钮对象**/
var activePopMenu = new Array();
var activePopMenuId = null;
var activePopTimer = null;
var activePopInMenu = null;
/***
* event 鼠标事件
* buttonId 按钮对应的ID, 菜单选项对应的ID为 buttonId + "_Items"
* disWidth 宽度补丁, 如果出现上下滚动条,占一定的宽度,挡住一下文字,需要使用该参数来扩展
* directType 0 下拉菜单,如果下拉高度不够,会显示向上,如果右边宽度不够,会向左展现
* 1 横向菜单,自动向右拉伸。
* 2 向上菜单
* 3 横向菜单,自动向左拉伸
T M B
L C R
**/
function clearActivePopTimer(){
if (activePopTimer != null){
clearTimeout(activePopTimer);
activePopTimer = null;
}
}
function popMenu(buttonId, maxHeight, disWidth, directType, outHideMenu){
//var button = $(buttonId);
// Get the target button element.
activePopInMenu = null;
clearActivePopTimer();
var pm;
if(activePopMenu[buttonId] == null){
pm = new Object();
activePopMenu[buttonId] = pm;
}else{
pm = activePopMenu[buttonId];
}
pm.button = document.getElementById(buttonId);
if(pm.menu == null){
pm.menu = $(buttonId + "_Items");
if(pm.menu==null) return;
pm.maxHeight = maxHeight;
pm.disWidth = disWidth;
pm.directType = directType;
if(outHideMenu && outHideMenu==true){
pm.outHideMenu = true;
}else{
pm.outHideMenu = false;
}
initMenu(pm);
}
if(!pm.outHideMenu){
Event.addEvent(pm.button, "onmouseout", hideMenu1);
}
//pm.button.blur();
//alert(Event.addEvent);
//button.attachEvent("onmouseout",hideMenu);
if(activePopMenuId == buttonId){
return;
}
if(activePopMenuId != buttonId){
hideActiveMenu();
showMenu(pm);
activePopMenuId = buttonId;
}else{
hideActiveMenu();
}
}
function initMenu(pm){
var menu = pm.menu;
if(!pm.outHideMenu){
Event.addEvent(menu, "onmouseout", hideMenu);
}
Event.addEvent(menu, "onmouseenter", inMenu);
Event.addEvent(menu, "onmouseover", inMenu);
menu.style.position = "absolute";
menu.style.display = "block";
menu.style.visibility = "hidden";
if(!pm.maxHeight){
pm.maxHeight = 1000;
}
var menuWidth = getChildNodeWidth(menu);
if(pm.disWidth){
menuWidth += pm.disWidth;
}
var button = pm.button;
if(button.offsetWidth > menuWidth){
var borderWidth = 0;
var borderLeftWidth = Element.getStyle(menu, "borderLeftWidth");
if(borderLeftWidth && parseInt(borderLeftWidth)){
borderWidth += parseInt(borderLeftWidth);
}
var borderRightWidth = Element.getStyle(menu, "borderRightWidth");
if(borderRightWidth && parseInt(borderRightWidth)){
borderWidth += parseInt(borderRightWidth);
}
menuWidth = button.offsetWidth - borderWidth;
}
var borderHeight = 0;
var borderTopHeight = Element.getStyle(menu, "borderTopWidth");
if(borderTopHeight && parseInt(borderTopHeight)){
borderHeight += parseInt(borderTopHeight);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -