标签:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="text" id="type"></input>
<p id="p"></p>
<script>
var html={}
//m
html.model ={
content:{
"0":"你好",
"1":"ok",
"2":"大家好",
"3":"你好",
"4":"ok",
"5":"大家好"
},
data:function(id){
if(!(id in this.content)){
var id = 0;
}
return this.content[id]
}
}
//c
html.controller = {
init:function(){
var id = html.view.id(); //获取id
var value = html.model.data(id); //通过id 过滤数据
html.view.init(value); //把数据加载到页面中
}
}
//v
html.view={
init:function(value){
document.getElementById("p").innerHTML= value;
},
id:function(){
return document.getElementById("type").value;
}
}
document.getElementById("type").onchange = html.controller.init;
</script>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/mojiewubu/p/4951246.html