添加数据 :
数据显示:
ClassModel.js源码 ::
复制代码 代码如下:
ClassModel =
{
create : function()
{
return function()
{
this.construct.apply(this, arguments);
}
}
}
Extend = function(desc, src)
{
for(var c in src)
{
desc[c] = src[c];
}
return desc;
}
Object.prototype.extend = function(src)
{
return Extend.apply(this, [this, src]);
}
addData.js源码::
复制代码 代码如下:
var insert = ClassModel.create();
var doc = new ActiveXObject("Msxml2.DOMDocument.3.0");
doc.load("books.xml");
var books;
insert.prototype =
{
construct : function(config)
{
this.id = config.id;
this.name = config.name;
this.author = config.author;
this.price = config.price;
this.publisher = config.publisher;
this.count = config.count;
this.insertData();
},
insertData : function()
{
var book = doc.createElement("book");
book.setAttribute("id", this.id);
var name = doc.createElement("name");
var nameValue = doc.createTextNode(this.name);
name.appendChild(nameValue);
book.appendChild(name);
var author = doc.createElement("author");
var authorValue = doc.createTextNode(this.author);
author.appendChild(authorValue);
book.appendChild(author);
var price = doc.createElement("price");
var priceValue = doc.createTextNode(this.price);
price.appendChild(priceValue);
book.appendChild(price);
var count = doc.createElement("count");
var countValue = doc.createTextNode(this.count);
count.appendChild(countValue);
book.appendChild(count);
var publisher = doc.createElement("publisher");
var publisherValue = doc.createTextNode(this.publisher);
publisher.appendChild(publisherValue);
book.appendChild(publisher);
if(doc.documentElement == null)
{
books = doc.createElement("books");
books.appendChild(book);
doc.appendChild(books);
}
else
{
books = doc.documentElement;
books.appendChild(book);
}
doc.save("books.xml");
}
}
window.js源码::
复制代码 代码如下:
var windows = ClassModel.create();
windows.prototype =
{
construct : function(jsonObject)
{
this.title = jsonObject.title;
this.width = jsonObject.width;
this.height = jsonObject.height;
this.titleColor = jsonObject.titleColor;
this.backgroundColor = jsonObject.backgroundColor;
this.LwHeight = (document.body.clientHeight - this.width) / 2; //让div在屏幕的中间
this.LwWidth = (document.body.clientWidth - this.height) / 2; //让div在屏幕的中间
this.content = jsonObject.content;
var loginWindow = this.createLoginBody();
var title = this.createLoginTitle();
loginWindow.appendChild(title);
var cont = this.createContent();
loginWindow.appendChild(cont);
document.body.appendChild(loginWindow);
},
createLoginBody: function() //创建登陆框, 即整个框
{
var loginWindow = document.createElement("div");
loginWindow.id = "dialog";
with(loginWindow.style)
{
border = "1px solid white";
position = "absolute";
width = this.width + "px";
height = this.height + "px";
top = this.LwHeight + "px";
left = this.LwWidth + "px";
backgroundColor = this.backgroundColor;
}
return loginWindow;
},
createLoginTitle:function() //创建 标题 即效果图的黑色标题
{
var title = document.createElement("div");
var table = document.createElement("table");
var tbody = document.createElement("tbody");
var tr = document.createElement("tr");
var td_1 = document.createElement("td");
var td_2 = document.createElement("td");
var close = document.createElement("a");
close.onclick = function()
{
document.body.removeChild(title.parentNode);
}
close.innerHTML = "X";
td_1.innerHTML = this.title;
with(title.style)
{
width = "100%";
height = this.height / 10 + "px";
backgroundColor = this.titleColor;
}
with(table.style)
{
color = "white";
fontSize = "12pt";
width = "100%";
backgroundColor = this.titleColor;
color = "red";
}
td_2.style.textAlign = "right";
td_2.appendChild(close);
tr.appendChild(td_1);
tr.appendChild(td_2);
tbody.appendChild(tr);
table.appendChild(tbody);
title.appendChild(table);
return title;
},
createContent : function()
{
var div = document.createElement("div");
if(typeof(this.content) == 'string')
{
div.innerHTML = this.content;
}else
{
div.appendChild(this.content);
}
with(div.style)
{
paddingLeft = "80px";
paddingTop = "50px";
float = "left";
width = "100%";
}
return div;
}
}
book_infor.js源码::
复制代码 代码如下: