<!doctype html><html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>邮箱前端实现</title> <style type="text/css"> *{ margin:0px; padding:0px; } .main{ margin:20px 30px; text-align:center; line-height:30px; } .left{ width:350px; height:450px; margin-top:30px; } .right{ width:600px; height:700px; margin-left:400px; margin-top:-480px; } .bottom{ border:1px solid #eee; width:100%; text-align:left; } #folderList li{ list-style: none; } #emailList li{ list-style: none; } #contentList li{ list-style: none; } .on{ background-color:#ccc; } #page{ text-align: right; margin-right: 30px; } #page a{ text-decoration:none; } </style> </head> <body> <div class="main" name="main"> <div class="left" name="left" id="left"> <ul id="folderList"></ul> </div> <div class="right" name="right" id="right"> <div id="page"> <a id="previous" href="javascript:void(0);">上一页</a> <a id="behind" href="javascript:void(0);">下一页</a> </div> <ul id="emailList"></ul> </div> <div class="bottom" name="bottom" id="bottom"> <ul id="contentList"></ul> </div> </div> </body><script type="text/javascript" src="http://www.mamicode.com/jquery.min.js"></script><script type="text/javascript" src="http://www.mamicode.com/underscore.js"></script><script type="text/javascript" src="http://www.mamicode.com/backbone.js"></script> <script type="text/javascript"> Model = Backbone.Model.extend({ initialize: function(){ //alert(‘Hey, you create me!‘); }, defaults: { pageIndex : 1, fid : -1, mid : -1 }, start : 1, //邮件开始 total : 20, //每页显示多少封邮件 firstAddFolder : true, //判断是否是第一次加载文件夹 firstAddTitle : true, //判断是否是第一次加载邮件列表 getResult : function(options){ $.ajax({ url : options.url, dataType : "json", //返回的数据类型,text 或者 json数据,建议为json type : "post", //传参方式,get 或post data : options.data, //传过去的参数,格式为 变量名:变量值 error : function(msg){ //若Ajax处理失败后回调函数,msg是返回的错误信息 //alert( "Ajax跳转处理失败"); //console.log(msg); options.error(msg.responseText); }, success: function(text) { //若Ajax处理成功后的回调函数,text是返回的信息 //alert("Ajax处理已成功:" + text); //console.log(text); options.success(text.responseText); } }); } }); //文件夹列表视图 ViewLeft = Backbone.View.extend({ el: $("#left"), initialize: function (options) { //初始化 //this.model = options.model; this.viewRight = options.viewRight; this.bindFidChangeEvent(); }, events: { "click #folderList li a": "checkIn", //事件绑定,给a标签绑定点击事件 }, checkIn: function(event){ var target = $(event.target); var fid = target.attr("fid"); //获取被点击的元素的fid this.model.set("fid",fid); target.parent().parent().find("li").removeClass("on"); //清除其余的.on target.parent().addClass("on"); //给被点击的对象绑定.on }, autoClick : function(){ //主动触发点击事件 $("#folderList li:first a").click(); }, bindFidChangeEvent: function () { var self = this; self.model.on("change:fid", function(){ //给fid绑定监听事件 self.model.firstAddTitle = true; self.model.start = 1; if(self.model.get("pageIndex")>1){ self.model.set("pageIndex",1); }else{ self.viewRight.getEmailTitle(self.model.get("fid")); } }); self.model.on("change:pageIndex", function(){ //给pageIndex绑定监听事件 self.model.firstAddTitle = true; self.viewRight.getEmailTitle(self.model.get("fid")); }); }, //获取文件夹列表 getFolder : function(){ var self = this; var sid = location.href.match(/sid=([^?#&]*)[?#&]?/)[1]; var data = http://www.mamicode.com/[ ‘
只要再引入jquery.min.js、underscore.js、backbone.js。然后用fiddler挂载这几个文件,从139邮箱登陆页登陆进去即可看到效果。