稍微改进了一下,下一步应该是封装对象,然后尝试组件话一个东东~?

时间:2021-03-30 22:06:51
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>我的临时思路实现</title>
<script type="text/javascript" src="Base.js"></script>
<script type="text/javascript" src="../JS/native/Error.js"></script>
<script type="text/javascript" src="../JS/native/Number.js"></script>
<script type='text/javascript'>

var US = {};
US.randomId = function(){
var word = ['a','b','c','d','e','f','g'];
var num = [1,2,3,4,5,6,7,8,9,0];
var result = '';
//16位iD
while(result.length<16){
var wordRandom = Base.Number.random4Int(0-word.length,word.length-1);
var numRandom = Base.Number.random4Int(0-num.length,num.length-1)
if(wordRandom>=0){
result += word[wordRandom];
}
if(numRandom>=0){
result += num[numRandom];
}
}
return result;
}


window.onload = function(){
var names = document.getElementsByName("showed");
var map = {
mapAll:{},
setItemsId:function(itemsId,obj){
this.mapAll[itemsId] = obj;
},
getHtmlObjByItemsId:function(itemsId){
return this.mapAll[itemsId];
},
getIdByItemsId:function(itemsId){
return this.mapAll[itemsId].getId();
},
setValueByItemsId:function(itemsId,value){
this.mapAll[itemsId].setValue(value);
},
getValueByItemsId:function(itemsId){
return this.mapAll[itemsId].getValue();
}
};
for(var i= 0,len=names.length;i<len;i++){
var _map = {
setId:function(id){
this.id = id;
},
getId:function(){
return this.id;
},
setItemsName:function(name){
this.itemsname = name;
},
setValue:function(value){
//根据节点类型 现模拟这个
document.getElementById(this.id).value = value;
},
getValue:function(){
return document.getElementById(this.id).value;
}
};
names[i].id = US.randomId();
_map.setId(names[i].id);
var htmlObj = document.getElementById(_map['id']);
var itemsName = null ,itemsId=null;
for(var j= 0,len_ = htmlObj.attributes.length;j<len_;j++){
if(htmlObj.attributes[j].nodeName=='itemsname'){
itemsName =htmlObj.attributes[j].value;
continue;
}
if(htmlObj.attributes[j].nodeName=='itemsid'){
itemsId =htmlObj.attributes[j].value;
continue;
}
if(itemsName!=null&&itemsId!=null){
break;
}
}
_map.setItemsName(itemsName);
map.setItemsId(itemsId,_map);
}
map.setValueByItemsId('two','two Text。。。。');
document.getElementById(map['one'].id).value='one Text...';
//console.log(document.getElementById(map['one'].id).value)
}




</script>
</head>

<input type="text" name="showed" itemsid="one" itemsname="first"/>
<input type="text" name="showed" itemsid="two" itemsname="seconed"/>

<body>

</body>
</html>