无为清净楼资源网 Design By www.qnjia.com
javascript 读取xml,写入xml 实现代码

添加数据 : javascript 读取xml,写入xml 实现代码

数据显示: javascript 读取xml,写入xml 实现代码

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源码::
复制代码 代码如下:
var doc = new ActiveXObject("Msxml2.DOMDocument.3.0");
doc.load("books.xml");
var query = ClassModel.create();
var v = 0;
query.prototype =
{
    construct : function()
    {
        this.bookInfor();
    },
    bookInfor : function()
    {
        var div = document.createElement("div");
        var root = doc.documentElement;
        if(root == null)
        {
            div.innerHTML = "no data";
            document.body.appendChild(div);
        }else
        {

        
        with(div.style)
        {
            marginLeft = "200px";
            overflow = "auto";
            border = "0px solid white";
            width = "605px";

        }
        var table = document.createElement("table");
        table.cellSpacing = "0";
        with(table.style)
        {    
            fontSize = "12pt";
            color = "white";
            border = "0px";
            width = "600px";

        }
        var tbody = document.createElement("tbody");
        var trHead = document.createElement("tr");
        with(trHead.style)
        {
            height = "20px";
            backgroundColor = "Transparent";

        }
        var tname = document.createElement("td");
        var tauthor = document.createElement("td");
        var tprice = document.createElement("td");
        var tCount = document.createElement("td");
        var tpublisher = document.createElement("td");

        tname.innerHTML = "名称";
        tauthor.innerHTML = "作者";
        tprice.innerHTML = "价格";
        tCount.innerHTML = "库存";
        tpublisher.innerHTML = "出版社";
        tname.style.borderBottom = "1px solid";
        tauthor.style.borderBottom = "1px solid";
        tprice.style.borderBottom = "1px solid";
        tCount.style.borderBottom = "1px solid";
        tpublisher.style.borderBottom = "1px solid";

        tname.style.width = "20%";
        tauthor.style.width = "20%";
        tprice.style.width = "20%";
        tCount.style.width = "20%";
        tpublisher.style.width = "20%";
        trHead.appendChild(tname);
        trHead.appendChild(tauthor);
        trHead.appendChild(tprice);
        trHead.appendChild(tCount);
        trHead.appendChild(tpublisher);

        tbody.appendChild(trHead);

    

        for(var c = 0; c < root.getElementsByTagName("book").length; c ++)
        {
            var roots = root.getElementsByTagName("book")[c];
            var id = roots.getAttribute("id");
            var name = roots.getElementsByTagName("name")[0].childNodes[0].nodeValue;
            var author = roots.getElementsByTagName("author")[0].childNodes[0].nodeValue;
            var price = roots.getElementsByTagName("price")[0].childNodes[0].nodeValue;
            var count = roots.getElementsByTagName("count")[0].childNodes[0].nodeValue;
            var publisher = roots.getElementsByTagName("publisher")[0].childNodes[0].nodeValue;
            var tr = document.createElement("tr");

            with(tr.style)
            {
                backgroundColor = "Transparent";
            }

            var tdName = document.createElement("td");
            var tdAuthor = document.createElement("td");
            var tdPrice = document.createElement("td");
            var tdCount = document.createElement("td");
            var tdPublisher = document.createElement("td");

            
            tdName.innerHTML = name;
            tdAuthor.innerHTML = author;
            tdPrice.innerHTML = price;
            tdCount.innerHTML = count;
            tdPublisher.innerHTML = publisher;

    
            tdName.id = "tdName" + c;
            tdAuthor.id = "tdAuthor" + c;
            tdPrice.id = "tdPrice" + c;
            tdCount.id = "tdCount" + c;
            tdPublisher.id = "tdPublisher" + c;
            tr.appendChild(tdName);
            tr.appendChild(tdAuthor);
            tr.appendChild(tdPrice);
            tr.appendChild(tdCount);
            tr.appendChild(tdPublisher);
            tbody.appendChild(tr);

            tdName.onmouseover = function(){
                document.body.style.cursor= "pointer";
                document.getElementById(this.id).style.backgroundColor = "darkred";
            }
            tdName.onmouseout = function(){
                document.body.style.cursor= "";
                document.getElementById(this.id).style.backgroundColor = "";
            }
            tdAuthor.onmouseover = function(){
                document.body.style.cursor= "pointer";
                document.getElementById(this.id).style.backgroundColor = "darkred";
            }
            tdAuthor.onmouseout = function(){
                document.body.style.cursor= "";
                document.getElementById(this.id).style.backgroundColor = "";
            }
            tdPrice.onmouseover = function(){
                document.body.style.cursor= "pointer";
                document.getElementById(this.id).style.backgroundColor = "darkred";
            }
            tdPrice.onmouseout = function(){
                document.body.style.cursor= "";
                document.getElementById(this.id).style.backgroundColor = "";
            }
            tdCount.onmouseover = function(){
                document.body.style.cursor= "pointer";
                document.getElementById(this.id).style.backgroundColor = "darkred";
            }
            tdCount.onmouseout = function(){
                document.body.style.cursor= "";
                document.getElementById(this.id).style.backgroundColor = "";
            }
            tdPublisher.onmouseover = function(){
                document.body.style.cursor= "pointer";
                document.getElementById(this.id).style.backgroundColor = "darkred";
            }
            tdPublisher.onmouseout = function(){
                document.body.style.cursor= "";
                document.getElementById(this.id).style.backgroundColor = "";
            }
        }

        table.appendChild(tbody);
        div.appendChild(table);

        document.body.appendChild(div);

        
    }    
}    
}    

标签:
javascript,xml

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。