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);
}
}
}
您可能感兴趣的文章: