⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receivedletter.js

📁 运用JSP/servlet/JavaBean 技术
💻 JS
字号:
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//创建异步通信对象
		
		//查信
		function toViewLetterPage()
		{
			var mailId = document.elementFromPoint(event.clientX, event.clientY).parentNode.lastChild.firstChild.data;
			xmlHttp.open("POST", "/QQMail/ViewLetterServlet", true);//打开与servlet的连接
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			var data = "mailId=" + mailId + "&mailStatus=0" +"&operation=setMailId";//构建参数
			xmlHttp.send(data);//发送请求
			parent.document.getElementById("main").src = "ViewLetter.html";
		}
		
		//Ajax异步通信查询收件箱
		function receiveLetter(userId, url)
		{
			xmlHttp.open("POST", url, true);//打开与servlet的连接
			xmlHttp.onreadystatechange = reply;//指定回调函数
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			var data = "userId=" + userId;//构建参数
			xmlHttp.send(data);//发送请求
		}
		
		function reply()
		{
			if(xmlHttp.readyState == 4)
			{
				if(xmlHttp.status == 200)
				{
					var xml = xmlHttp.responseXML;//获取返回的xml对象
					var notReadMails = xml.getElementsByTagName("notreadmail");//获得未读信件相关信息
					var readYetMails = xml.getElementsByTagName("readyetmail");//获得已读信件相关信息
					var notReadLen = notReadMails.length;//未读信件个数
					var readYetLen = readYetMails.length;//已读信件个数
					if(notReadLen == 0 && readYetLen == 0)//如果没有信件,那么返回
					{
						(document.getElementById("body")).innerHTML = "<span>无信件</span>";
						return;
					}
					else//有信件,那么创建信件table
					{
						var len = notReadLen + readYetLen;
						var whoSendes = new Array(len);
						var mailTitles = new Array(len);
						var mailIds = new Array(len);
						for(var i = 0; i < len; i++)
						{
							if(i < notReadLen)
							{
								whoSendes[i] = notReadMails[i].firstChild.firstChild.data;
								mailTitles[i] = notReadMails[i].firstChild.nextSibling.firstChild.data;
								mailIds[i] = notReadMails[i].lastChild.firstChild.data;
							}
							else
							{
								whoSendes[i] = readYetMails[i - notReadLen].firstChild.firstChild.data;
								mailTitles[i] = readYetMails[i - notReadLen].firstChild.nextSibling.firstChild.data;
								mailIds[i] = readYetMails[i - notReadLen].lastChild.firstChild.data;
							}
						}
						createTable(whoSendes, mailTitles, mailIds, notReadLen);
					}
				}
			}
		}
		
		function createTable(whoSendeds, mailTitles, mailIds, notReadLen)
		{
			var style = "style = 'color: #1E5494; font-weight: bolder;'";
			var body = document.getElementById("body");
			var tableHtml = "<table>"
					+"<tr class='rowTitle'>"
					+"<th class='column1'><input type='checkbox' id='controlAllCheckbox' onclick='changeOther();' /></th>"
					+"<th class='column2'>发件人</th>"
					+"<th class='column3'>主题</th>"
					+"<th></th>"
					+"</tr>";
			for(var i = 0; i < whoSendeds.length; i++)
			{
				if(notReadLen-- == 0)
				{
					style = "";
				}
				tableHtml += "<tr class='rowData'>"
					+"<td class='data1'><input type='checkbox' name='data' /></td>"
					+"<td class='data2' " + style + " onmouseover='changeStyle();' onmouseout='turnBack();' onclick='toViewLetterPage();'>"
					+whoSendeds[i]
					+"</td>"
					+"<td class='data3' " + style + " onmouseover='changeStyle();' onmouseout='turnBack();' onclick='toViewLetterPage();'>"
					+mailTitles[i]
					+"</td>"
					+"<td style='color: white; cursor: default;'>"
					+mailIds[i]
					+"</td>"
				    +"</tr>";
			}
			tableHtml += "</table>";
			body.innerHTML = tableHtml;
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -