关于JS获取struts iterate对象及提醒功能

今天下午要做项目中的一个小功能:付款提醒功能,到付款时间用红色显示,做成之后如下图
[img]
http://cbfmai.iteye.com/upload/picture/pic/42819/f5402300-d53f-32e4-8629-ad50ad271b6a.jpg
[/img]

如下代码是struts iterate对象:
			<table width="100%" border="1" class="listtable" id="table">
				<tr class="listheader">
					<td width="30" align="center" nowrap>
						序号
					</td>
					<td width="30" align="center" nowrap>
						<input type="checkbox" name="allbox" onclick="allboxclick()">
					</td>
					<td width="30" align="center" nowrap>
						编辑
					</td>
					<td width="100" align="center" nowrap>
						<gpt:PageSortColumn column="obj.sn"
							htmlproperty="class='sortcolumn'">合同编号</gpt:PageSortColumn>
					</td>
					<td width="100" align="center" nowrap>
						<gpt:PageSortColumn column="obj.name"
							htmlproperty="class='sortcolumn'">合同名称</gpt:PageSortColumn>
					</td>
					<td width="100" align="center" nowrap>
						<gpt:PageSortColumn column="obj.money"
							htmlproperty="class='sortcolumn'">金额</gpt:PageSortColumn>
					</td>
					<td width="100" align="center" nowrap>
						<gpt:PageSortColumn column="obj.deadline"
							htmlproperty="class='sortcolumn'">期限</gpt:PageSortColumn>
					</td>
					<td width="100" align="center" nowrap>
						<gpt:PageSortColumn column="obj.principal"
							htmlproperty="class='sortcolumn'">负责人</gpt:PageSortColumn>
					</td>
					<td width="100" align="center" nowrap>
						<gpt:PageSortColumn column="obj.paytime"
							htmlproperty="class='sortcolumn'">付款时间</gpt:PageSortColumn>
					</td>
				</tr>
				<logic:iterate id="obj" name="OBJLIST" scope="request">
					<tr class="listrow" onclick="hL(this)" onmouseout="out(this)">
						<gpt:TD><%=++i%></gpt:TD>
						<td width="30" align="center">
							<input type="checkbox" name="delbox" onclick="delboxclick();"
								value="<bean:write name="obj" property="id"/>" />
						</td>
						<td width="30" align="center">
							<img src="../../resources/images/icon/icon_modify.gif"
								class="icon"
								onclick="mod(400,380,<bean:write name='obj' property='id'/>);" />
						</td>
						
							<bean:write name="obj" property="sn" />					
						
							<bean:write name="obj" property="name" />
						
							<bean:write name="obj" property="money" />
					
							<bean:write name="obj" property="deadline" />
					
							<bean:write name="obj" property="principal" />
					
							<bean:write name="obj" property="paytime" />
					
					</tr>
				</logic:iterate>
			</table>


下面是在窗体自动加载时调用JS来提醒是否到了付款日期(我这里是做提前一天提醒)
代码如下:
    	// 显示红色
   		window.onload = function(){
   		
   			//得到这个表
   			var array = document.getElementById("table");
   			
   			//得到这个表共有多少行
   			var length = array.rows.length - 1;
   			var i=1;
   			
   			//循环判断是否超过付款日期
   			for(i=1; i <= length; i++){
   				var date = new Date();
   				var year = date.getFullYear();
   				var month = date.getMonth()+1;
   				var day = date.getDate() - 1;
//因为我这里是第7列,所以cells[6]
   				var time = array.rows[i].cells[6];
   				var timeArray = new Array();
   				timeArray[0] = year;
   				timeArray[1] = month;
   				timeArray[2] = day;
   				var j = 0;
   				var k = 0;
   				var subStrOfTime = time.innerText.substr(0,10);
   				for(j = 0; j < subStrOfTime.split("-").length; j++){
   					var a = subStrOfTime.split("-")[j];
   					// 格式化后相比较
   					if(a.replace(/\b(0+)/gi,"")<=timeArray[j])
   					{	
   						k ++ ;
   					}
   				}
   				if(k == 3){
   					array.rows[i].style.backgroundColor="#FF6900";
   				}
   			}
   		}


最后的功能如第一张图片!
可能JS写的有些不好看,或者是说比较冗繁吧,呵呵,毕竟是个JS新手!
哎,今天下午终于可以稍微上上小网了!!

你可能感兴趣的:(html,struts,J#)