<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript">
var skydao = {
obj: null,
init: function(obj) {
this.obj = this.createTag(obj['tag']);
this.setAttribute(obj['attribute'])
this.setChild(obj['child']);
return this.obj;
},
createTag: function(tag) {
return document.createElement(tag);
},
createText: function(text) {
return document.createTextNode(text);
},
setChild: function(obj) {
this.obj.appendChild(this.createText(obj));
},
setAttribute: function(obj) {
for (var key in obj) {
if (key == 'class') {
this.obj['className'] = obj[key];
}
this.obj[key] = obj[key];
}
}
}
window.onload = function() {
var attribute = {'id': 'place', 'class': 'preview', 'title': '预留区' };
var divObj = skydao.init(
{
'tag': 'div',
'attribute': attribute,
'child': 'this previewplace'
}
);
document.body.appendChild(divObj);
}
</script>
</head>
<body>
</body>
</html>
使用JavaScript创建自定义对象
最新推荐文章于 2024-09-11 15:33:18 发布