window.js 主要包含了頁(yè)面的一些操作
更新時(shí)間:2009年12月23日 18:48:00 作者:
主要是獲取頁(yè)面元素的一些信息,所以明名為window.js,想要學(xué)習(xí)的朋友可以參考下。
復(fù)制代碼 代碼如下:
//處理頁(yè)面異常
function Exception() {
}
//頁(yè)面元素共同接口
function View() {
//頁(yè)面元素
this.element = null;
//文字顏色
this.color = null;
//設(shè)置樣式
this.setStyle = function(name, value) {
eval("this.element.style." + name + " = '" + value + "'");
}
//獲取樣式
this.getStyle = function(name) {
return eval("this.element.style." + name);
}
//設(shè)置浮動(dòng)樣式
this.setFloat = function(styleFloat) {
this.setStyle("styleFloat", styleFloat);
}
//設(shè)置背景色
this.setBackgroundColor = function(backgroundColor) {
this.setStyle("backgroundColor", backgroundColor);
}
//獲取背景色
this.getBackgroundColor = function() {
return this.getStyle("backgroundColor");
}
//設(shè)置對(duì)象寬度
this.setWidth = function(width) {
//alert(width);
this.setStyle("width", width);
}
//設(shè)置對(duì)象寬度
this.setHeight = function(height) {
this.setStyle("height", height);
}
//設(shè)置頁(yè)面定位
this.setPosition = function(position) {
this.setStyle("position", position);
}
//設(shè)置層
this.setZIndex = function(zIndex) {
this.setStyle("zIndex", zIndex);
}
//左邊距離
this.setLeft = function(left) {
this.setStyle("left", left);
}
//上邊距離
this.setTop = function(top) {
this.setStyle("top", top);
}
//是否換行
this.setWhiteSpace = function(whiteSpace) {
this.setStyle("whiteSpace", whiteSpace);
}
this.setMargin = function(margin) {
this.setStyle("margin", margin);
}
this.setPadding = function(padding) {
this.setStyle("padding", padding);
}
//設(shè)置屬性
this.setAttributeIsHave = function(attrName, value) {
eval("this.element.setAttribute('" + attrName + "', '" + value + "')");
}
this.setId = function(id) {
this.setAttributeIsHave("id", id);
}
this.setInnerText = function(innertext) {
this.setAttributeIsHave("innerText", innertext);
}
//加入自定義屬性
this.setAttributeIsNot = function(attrName, value) {
var attr = document.createAttribute(attrName);
attr.value = value;
this.element.setAttributeNode(attr);
}
//事件監(jiān)聽(tīng)
this.eventListener = function(eventName, exec) {
this.element.attachEvent(eventName, exec);
}
//鼠標(biāo)移入對(duì)象事件
this.onmouseenterListener = function(exec) {
this.eventListener("onmouseenter", exec);
}
//鼠標(biāo)移出對(duì)象事件
this.onmouseleaveListener = function(exec) {
this.eventListener("onmouseleave", exec);
}
//鼠標(biāo)單擊對(duì)象事件
this.onclickListener = function(exec) {
this.eventListener("onclick", exec);
}
}
//單一元素
function Single() {
View.call(this);
}
//可以有子元素
function Multi() {
View.call(this);
//子元素集合
this.childElementList = new Array();
//加入子元素
this.addView = function(childElement) {
if(this.element == null) {
//待加入異常信息
return;
}
this.childElementList[this.childElementList.length] = childElement;
}
//關(guān)聯(lián)子元素
this.appendChildElement = function(childElement) {
this.element.appendChild(childElement.element);
}
//顯示元素
this.show = function() {
for(var i = 0; i < this.childElementList.length; i++) {
var childElement = this.childElementList[i];
this.appendChildElement(childElement);
childElement.show();
}
}
}
//面板
function Panel() {
Multi.call(this);
//創(chuàng)建頁(yè)面元素
this.element = document.body;
}
//行布局
function LineLayout() {
Multi.call(this);
this.element = document.createElement("div");
}
//左布局
function LeftLayout() {
Multi.call(this);
this.element = document.createElement("div");
this.setFloat("left");
}
//右布局
function RightLayout() {
Multi.call(this);
this.element = document.createElement("div");
this.setFloat("right");
}
function Menu() {
Multi.call(this);
this.element = document.createElement("div");
this.setWidth("100%");
var clickListener = function() {
return;
};
var moveInBackgroundColor = "red";
var moveOutBackgroundColor = this.getBackgroundColor();
this.show = function() {
var menuItem = null;
var menuEntiy = null;
for(var i = 0; i < this.childElementList.length; i++) {
menuItem = new MenuItem();
menuEntiy = this.childElementList[i];
menuItem.addMenuEntity(menuEntiy);
menuItem.onmouseenterListener(moveInMenuItem);
menuItem.onmouseleaveListener(moveOutMenuItem);
menuItem.onclickListener(this.clickMenuItem );
menuItem.setPadding("0 5px 0 5px");
this.appendChildElement(menuItem);
}
}
this.setClickListener = function(exec) {
clickListener = exec;
}
function moveInMenuItem() {
event.srcElement.style.backgroundColor = moveInBackgroundColor;
}
function moveOutMenuItem() {
event.srcElement.style.backgroundColor = moveOutBackgroundColor;
}
this.clickMenuItem = function() {
var child = clickListener();
document.body.appendChild(child.element);
child.setLeft(event.srcElement.offsetLeft);
child.setTop(event.srcElement.offsetParent.offsetTop + event.srcElement.clientHeight);
child.show();
}
}
function ChildMenu() {
Multi.call(this);
this.element = document.createElement("div");
this.setPosition("absolute");
this.setZIndex(100);
this.setBackgroundColor("#ccffcc");
var moveInBackgroundColor = "red";
var moveOutBackgroundColor = this.getBackgroundColor();
this.show = function() {
var menuItem = null;
var menuEntiy = null;
for(var i = 0; i < this.childElementList.length; i++) {
menuItem = new MenuItem();
menuItem.setFloat("none");
menuEntiy = this.childElementList[i];
menuItem.addMenuEntity(menuEntiy);
menuItem.onmouseenterListener(moveInMenuItem);
menuItem.onmouseleaveListener(moveOutMenuItem);
//menuItem.onclickListener(clickMenuItem);
menuItem.setPadding("0 5px 0 15px");
this.appendChildElement(menuItem);
}
}
function moveInMenuItem() {
event.srcElement.style.backgroundColor = moveInBackgroundColor;
}
function moveOutMenuItem() {
event.srcElement.style.backgroundColor = moveOutBackgroundColor;
}
}
function MenuEntiy(id, name, action) {
this.id = id;
this.name = name ;
this.action = action;
}
function MenuItem() {
Single.call(this);
this.element = document.createElement("div");
this.setFloat("left");
this.setWhiteSpace("nowrap");
this.addMenuEntity = function(menuEntity) {
this.setId(menuEntity.id);
this.setInnerText(menuEntity.name);
this.setAttributeIsNot("action", menuEntity.action);
}
}
相關(guān)文章
JS實(shí)現(xiàn)使用POST方式發(fā)送請(qǐng)求
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)使用POST方式發(fā)送請(qǐng)求,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08基于JS實(shí)現(xiàn)操作成功之后自動(dòng)跳轉(zhuǎn)頁(yè)面
這篇文章主要介紹了基于JS實(shí)現(xiàn)操作成功之后自動(dòng)跳轉(zhuǎn)頁(yè)面的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09javascript showModalDialog,open取得父窗口的方法
showModalDialog,open取得父窗口的代碼,需要的朋友可以參考下。2010-03-03JavaScript中清空數(shù)組的方法總結(jié)
本文給大家總結(jié)了三種js清空數(shù)組的方法,每種方法都與眾不同,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-12-12JS獲取多維數(shù)組中相同鍵的值實(shí)現(xiàn)方法示例
這篇文章主要介紹了JS獲取多維數(shù)組中相同鍵的值實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了JS數(shù)組遍歷、判斷、鍵值獲取等操作技巧,需要的朋友可以參考下2017-01-01JavaScript面向?qū)ο笕齻€(gè)基本特征實(shí)例詳解【封裝、繼承與多態(tài)】
這篇文章主要介紹了JavaScript面向?qū)ο笕齻€(gè)基本特征,結(jié)合實(shí)例形式詳細(xì)分析了JavaScript面向?qū)ο笕齻€(gè)基本特征封裝、繼承與多態(tài)的概念、原理、用法與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05前端如何利用CryptoJS實(shí)現(xiàn)數(shù)據(jù)信息的加密詳解
這篇文章主要給大家介紹了關(guān)于前端如何利用CryptoJS實(shí)現(xiàn)數(shù)據(jù)信息加密的相關(guān)資料,前端解密解密工具Cryptojs提供了前端加密解密的工作,包括常用的MD5、BASE64、SHA1、AES等加密解密方法,需要的朋友可以參考下2023-11-11