这么我要根据时间差来判断,我点击调试过,点击按钮的id都是对的,但是里面的开始时间和结束时间总是第一条数据的开始时间和结束时间,求大神指导,已经试过很多方法,怎么弄都不行!!!!
function arrove(idpermision) { //根据假单的时间间隔来判断,如果是小于三天就是经理审批,大于三天小于七天就是经理和副总审批,大于七天就是一级一级的审批上来最后由hr审批
//
//判断请假时间
alert(idpermision);
var star = document.getElementById("permsstart").value;//获取页面的开始时间
var end = document.getElementById("permsend").value;//获取页面的结束时间
var time1 = new Date(Date.parse(star)).getTime();
var time2 = new Date(Date.parse(end)).getTime();
alert(time1);
alert(time2);
var day = (time2 -time1)/(24*3600*1000); //判断结束时间和开始时间的间隔天数
var s="<%=session.getAttribute("pos")%>"; //根据角色添加间隔时间的判断用户是否可以点击
var posname = document.getElementById("PosName").value;
alert(day);
///判断当前申请者为职员,根据时间来判断
if(posname.indexOf("职员") >= 0 ){
if( s == "经理" ){ //在小于三天当前w可以修改其他都不可以修改
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
return true;
}else {
if( day >3 && s == "副总" && posname.indexOf("职员") >= 0 ){
s.disabled = false;
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
}
if( day > 7 && s == "HR" && posname.indexOf("职员") >= 0 ){
s.disabled = false;
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
}
}
if( s == "副总" && day >3 ){
s.disabled = false;
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
}
if(s == "HR" && day > 7 ){
s.disabled = false;
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
}
document.getElementById("button").disabled = true;
document.getElementById("button1").disabled = true;
}
///////////////////////////////////////////////////////////////判断当前申请者为经理由副总审批,根据时间判断
if(posname.indexOf("经理")>= 0){
if(s == "副总"){
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
return true;
}else {
if( day >3 && s == "HR" ){
s.disabled = false;
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
}
document.getElementById("button").disabled = true;
document.getElementById("button1").disabled = true;
}
}
/////////////////////////////////////////////////////////////////判断当前申请者是副总,就是hr审批
if(posname.indexOf("副总")>= 0){
if(s == "HR"){
document.myform.action = "permapprconf.jsp?idpermision="+idpermision;
document.myform.submit();
return true;
}
}
}
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/oa","root", "123456");
String query1="SELECT a.idpermision, c.permstype, b.EmpName, b.EmpNo, d.DepName, e.PosName, a.permsstart, a.permsend, a.leavetype, a.permsreason, a.permstatus, a.CreatedDate,a.approvedreason,a.approvedby,b.username"
+ " FROM oa.permision a LEFT JOIN oa.employee b on a.idEmployee=b.idEmployee LEFT JOIN oa.permstype c on a.idpermstype= c.idpermstype LEFT JOIN oa.department d on b.idDep=d.idDep LEFT JOIN oa.position e on b.idPosition=e.idPosition "
+ "WHERE Concat(b.EmpLead, '', b.EmpManage, '', b.EmpGM, '', b.EmpVP) like '%" + EmpName + "%' and (a.approvedby not like '%"+account1+"%' OR a.approvedby is null) order by a.CreatedDate desc ";
Statement con1 = connection.createStatement() ;
ResultSet accountInfo=con1.executeQuery(query1);
%>
<TABLE width="85%" height="108" BORDER="1" cellpadding="5" >
<TR>
<TH>假单类型</TH>
<TH>姓名</TH>
<TH>员工工号</TH>
<TH>部门</TH>
<TH>角色</TH>
<TH>开始时间</TH>
<TH>结束时间</TH>
<TH>原因</TH>
<TH>状态</TH>
<TH>创建时间</TH>
<TH>审批理由</TH>
<TH>申请</TH>
</TR>
<% while(accountInfo.next()){ %>
<TR>
<TD> <%= accountInfo.getString(2) %></TD>
<TD> <%= accountInfo.getString(3) %></TD>
<TD> <%= accountInfo.getString(4) %></TD>
<TD> <%= accountInfo.getString(5) %></TD>
<TD> <%= accountInfo.getString(6) %></TD>
<TD> <%= accountInfo.getString(7) %></TD>
<TD> <%= accountInfo.getString(8) %></TD>
<TD> <%= accountInfo.getString(9) %> - <%= accountInfo.getString(10) %></TD>
<TD> <%= accountInfo.getString(11) %></TD>
<TD> <%= accountInfo.getString(12) %></TD>
<TD> <%= accountInfo.getString(13) %></TD>
<input id="idpermision" name="idpermision" type="hidden" value="<%= accountInfo.getString(1)%>"/>
<th colspan="2">
<input id="button" name ="button" type="button" onclick="arrove(<%=accountInfo.getString(1)%>)" value='通过'/>
<input id="button1" name ="button1" type="button" onclick="show(<%=accountInfo.getString(1)%>)" value='驳回'/>
</th>
<input id="permsstart" type="hidden" name="permsstart" value= "<%= accountInfo.getString(7)%>"/>
<input id="permsend" type="hidden" name="permsend" value= "<%= accountInfo.getString(8)%>" />
<input id="approvedreason" name="approvedreason" type = "hidden" value=""></input>
<input id="permstatus" type="hidden" name="permstatus" value= <%= accountInfo.getString(11) %>;"/>
<input id="PosName" type="hidden" name="PosName" value= <%= accountInfo.getString(6) %>;"/>
<input id="EmpName" type="hidden" name="EmpName" value= <%= accountInfo.getString(2) %>;"/>
<input id="username" type="hidden" name="username" value= <%= accountInfo.getString(14) %>;"/>
</TR>
<% } %>
</TABLE>
</CENTER>
</form>
</BODY>
把你提交那块的代码贴出来看一下
document.myform.submit();
你form表单提交 里面的input的值,是不是一直是 第一条 数据,没有改?
应为你的时间id都重复了,id要唯一。重复的话document.getElementById只能获取最先出现的dom对象,就是你的第一条记录
给这2个控件添加accountInfo.getString(1)变为唯一
<th colspan="2">
<input id="button" name ="button" type="button" onclick="arrove(<%=accountInfo.getString(1)%>)" value='通过'/>
<input id="button1" name ="button1" type="button" onclick="show(<%=accountInfo.getString(1)%>)" value='驳回'/>
</th>
<input id="permsstart<%=accountInfo.getString(1)%>" type="hidden" name="permsstart" value= "<%= accountInfo.getString(7)%>"/>
<input id="permsend<%=accountInfo.getString(1)%>" type="hidden" name="permsend" value= "<%= accountInfo.getString(8)%>" />
获取时加上idpermision
function arrove(idpermision) {
var star = document.getElementById("permsstart"+idpermision).value;//获取页面的开始时间
var end = document.getElementById("permsend"+idpermision).value;//获取页面的结束时间
解决办法:
(1)function arrove(idpermision, 开始时间, 结束时间,PosName ) {}
(2)就是你的input的id不能相同,需要像楼上说得(感觉这种方式是不是生成的页面代码好多啊)
(3)传递当前点击对象,然后找到当前列的其他你需要的参数,不知道这种是不是jquery更方便