1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>MVC</title> 6 </head> 7 <body> 8 <script type="text/javascript"> 9 // 定义三个对象,模拟Model, View, Controller 10 var M = {}, V = {}, C = {}; 11 12 // Model负责数据 13 M.data = 'This is simple MVC'; 14 15 // View负责渲染数据到页面上 16 V.render = (M) => { 17 alert(M.data); 18 } 19 20 // Controller作为Model和View之间的桥梁 21 C.handleOne = () => { 22 V.render(M); 23 } 24 25 // 在加载页面的时候执行controller中的方法来串联整个MVC 26 window.onload = C.handleOne; 27 </script> 28 </body> 29 </html>