Js对象操作的例子
2007-05-21 09:45
302 查看
/**
* @author 118pc.com
*/
var NetShop = new Object();
NetShop.util = {
createTd: function(htmlString, cssClass){
var td = document.createElement('td');
td.className = cssClass;
td.innerHTML = htmlString;
return td;
}
}
NetShop.BuyCarObject = function(dataTable){
var buyCar = new Object();
for(var i = 0; i < dataTable.Rows.length; i++){
var dataRow = dataTable.Rows[i]
var buyCarInfo = new Object();
buyCarInfo.title = dataRow['Title'];
buyCarInfo.number = parseInt(dataRow['num']);
buyCarInfo.price = parseFloat(dataRow['price']);
buyCarInfo.count = buyCarInfo.number * buyCarInfo.price;
var key = dataRow['userId'];
if(!buyCar.hasKey(key)){
buyCar[key] = new Array();
buyCar[key].companyName = dataRow['CompanyName'];
}
buyCar[key].push(buyCarInfo);
}
return buyCar;
}
NetShop.Page = new Object();
NetShop.Page.BuyCar = new Object();
NetShop.Page.BuyCar.Panel = function(dataTable){
var buyCarObject = new NetShop.BuyCarObject(dataTable);
var panel = document.createElement('div');
panel.className = 'panel';
for(key in buyCarObject){
var buyCarInfoList = buyCarObject[key];
if(buyCarInfoList.length > 0 && buyCarInfoList.companyName){
var header = document.createElement('div');
header.className = 'header';
header.appendChild(document.createTextNode(buyCarInfoList.companyName));
panel.appendChild(header);
for(var i = 0; i < buyCarInfoList.length; i++){
var buyCarInfo = buyCarInfoList[i];
var table = document.createElement('table');
table.cellpadding = 0;
table.cellspacing = 0;
table.border = 0;
table.className = 'table';
panel.appendChild(table);
var tBody = document.createElement('tbody');
table.appendChild(tBody);
var tr = document.createElement('tr');
tBody.appendChild(tr);
var td1 = NetShop.util.createTd(buyCarInfo.title, 'td1');
tr.appendChild(td1);
var td2 = NetShop.util.createTd(buyCarInfo.number, 'td2');
tr.appendChild(td2);
var td3 = NetShop.util.createTd(buyCarInfo.price + ' 鈧?, 'td2');
tr.appendChild(td3);
var td4 = NetShop.util.createTd(buyCarInfo.count + ' 鈧?, 'td2');
tr.appendChild(td4);
}
}
}
var bottom = document.createElement('div');
bottom.className = 'bottom';
panel.appendChild(bottom);
var closeBtn = document.createElement('input');
closeBtn.type = 'button';
closeBtn.value = 'close me';
closeBtn.className = 'closeBtn';
closeBtn.onclick = function(){
panel.parentNode.style.visibility = 'hidden'
};
bottom.appendChild(closeBtn);
return panel;
}
* @author 118pc.com
*/
var NetShop = new Object();
NetShop.util = {
createTd: function(htmlString, cssClass){
var td = document.createElement('td');
td.className = cssClass;
td.innerHTML = htmlString;
return td;
}
}
NetShop.BuyCarObject = function(dataTable){
var buyCar = new Object();
for(var i = 0; i < dataTable.Rows.length; i++){
var dataRow = dataTable.Rows[i]
var buyCarInfo = new Object();
buyCarInfo.title = dataRow['Title'];
buyCarInfo.number = parseInt(dataRow['num']);
buyCarInfo.price = parseFloat(dataRow['price']);
buyCarInfo.count = buyCarInfo.number * buyCarInfo.price;
var key = dataRow['userId'];
if(!buyCar.hasKey(key)){
buyCar[key] = new Array();
buyCar[key].companyName = dataRow['CompanyName'];
}
buyCar[key].push(buyCarInfo);
}
return buyCar;
}
NetShop.Page = new Object();
NetShop.Page.BuyCar = new Object();
NetShop.Page.BuyCar.Panel = function(dataTable){
var buyCarObject = new NetShop.BuyCarObject(dataTable);
var panel = document.createElement('div');
panel.className = 'panel';
for(key in buyCarObject){
var buyCarInfoList = buyCarObject[key];
if(buyCarInfoList.length > 0 && buyCarInfoList.companyName){
var header = document.createElement('div');
header.className = 'header';
header.appendChild(document.createTextNode(buyCarInfoList.companyName));
panel.appendChild(header);
for(var i = 0; i < buyCarInfoList.length; i++){
var buyCarInfo = buyCarInfoList[i];
var table = document.createElement('table');
table.cellpadding = 0;
table.cellspacing = 0;
table.border = 0;
table.className = 'table';
panel.appendChild(table);
var tBody = document.createElement('tbody');
table.appendChild(tBody);
var tr = document.createElement('tr');
tBody.appendChild(tr);
var td1 = NetShop.util.createTd(buyCarInfo.title, 'td1');
tr.appendChild(td1);
var td2 = NetShop.util.createTd(buyCarInfo.number, 'td2');
tr.appendChild(td2);
var td3 = NetShop.util.createTd(buyCarInfo.price + ' 鈧?, 'td2');
tr.appendChild(td3);
var td4 = NetShop.util.createTd(buyCarInfo.count + ' 鈧?, 'td2');
tr.appendChild(td4);
}
}
}
var bottom = document.createElement('div');
bottom.className = 'bottom';
panel.appendChild(bottom);
var closeBtn = document.createElement('input');
closeBtn.type = 'button';
closeBtn.value = 'close me';
closeBtn.className = 'closeBtn';
closeBtn.onclick = function(){
panel.parentNode.style.visibility = 'hidden'
};
bottom.appendChild(closeBtn);
return panel;
}
相关文章推荐
- js 面向对象操作例子
- 扩展JS Date对象时间格式化功能的小例子
- 扩展JS Date对象时间格式化功能的小例子
- js定义对象简单学习例子
- C++中对象间的相互操作例子(2005-6-1)
- js实现弹出窗口、页面变成灰色并不可操作的例子分享
- JS操作json对象key、value
- js操作Json数据,JSON对象与字符串转化
- JS操作图片(增,删,改) 例子
- js学习--DOM操作详解大全一(浏览器对象)
- js操作frameset frame 对象
- js 操作frameset frame 对象
- 认识JQuery,JQuery的优势、语法、多库冲突、JS原生对象和JQuery对象之间相互转换和DOM操作,常用的方法
- JS中常用操作技巧(页面动态增加div,contain方法扩展,JSON对象鱼字符串转换)
- js对dom对象的操作之select元素:js不能获取select对象
- js中json字符串对象互转的例子
- js中json字符串对象互转的例子
- 使用操作对象的简单例子(63)
- js操作节点对象注意事项
- JS 中 Math 对象的【三角函数】的用法与实战例子【打靶游戏】 | Math.tan(), Math.cos(), Math.sin()