欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript 讀取xml,寫入xml 實現(xiàn)代碼

 更新時間:2009年07月10日 21:27:23   作者:  
javascript xml讀取,寫入xml 實現(xiàn)代碼

添加數據 :

數據顯示:

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() //創(chuàng)建登陸框, 即整個框
{
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() //創(chuàng)建 標題 即效果圖的黑色標題
{
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);

        
    }    
}    
}    

相關文章

  • js+ajax實現(xiàn)的A*游戲路徑算法整理

    js+ajax實現(xiàn)的A*游戲路徑算法整理

    js+ajax實現(xiàn)的A*游戲路徑算法整理...
    2007-05-05
  • 分析uniapp入門之nvue爬坑記

    分析uniapp入門之nvue爬坑記

    uni-app的nvue說白了就是weex的那一套東西,uni-app集成了weex的 SDK,也就實現(xiàn)了App端的原生渲染能力。本文將介紹uniapp遇到的一些坑,分享給大家。
    2021-06-06
  • javascript中call,apply,callee,caller用法實例分析

    javascript中call,apply,callee,caller用法實例分析

    這篇文章主要介紹了javascript中call,apply,callee,caller用法,結合實例形式分析了javascript中call,apply,callee,caller功能、使用方法及相關操作注意事項,需要的朋友可以參考下
    2019-07-07
  • 利用JS響應式修改vue實現(xiàn)頁面的input值

    利用JS響應式修改vue實現(xiàn)頁面的input值

    這篇文章主要給大家介紹了關于如何利用JS響應式修改vue實現(xiàn)頁面的input值,文中通過示例代碼介紹的非常詳細,對大家學習或者使用JS具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-09-09
  • 微信小程序實現(xiàn)橫向增長表格的方法

    微信小程序實現(xiàn)橫向增長表格的方法

    這篇文章主要介紹了微信小程序實現(xiàn)橫向增長表格的方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-07-07
  • JS實現(xiàn)上傳文件顯示進度條

    JS實現(xiàn)上傳文件顯示進度條

    這篇文章主要為大家詳細介紹了JS實現(xiàn)上傳文件顯示進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • mustache.js實現(xiàn)首頁元件動態(tài)渲染的示例代碼

    mustache.js實現(xiàn)首頁元件動態(tài)渲染的示例代碼

    這篇文章主要介紹了mustache.js實現(xiàn)首頁元件動態(tài)渲染的示例代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • 利用JS屏蔽頁面中的Enter按鍵提交表單的方法

    利用JS屏蔽頁面中的Enter按鍵提交表單的方法

    下面小編就為大家?guī)硪黄肑S屏蔽頁面中的Enter按鍵提交表單的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-11-11
  • layer實現(xiàn)關閉彈出層刷新父界面功能詳解

    layer實現(xiàn)關閉彈出層刷新父界面功能詳解

    這篇文章主要介紹了layer實現(xiàn)關閉彈出層刷新父界面功能,結合實例形式分析了使用layui的layer在關閉彈出層時刷新父界面的常用實現(xiàn)技巧與相關操作注意事項,需要的朋友可以參考下
    2017-11-11
  • 淺談javascript的閉包

    淺談javascript的閉包

    本文介紹了javascript閉包的相關知識。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-01-01

最新評論