<div id="workshowDiv">
<form action="#" method="post" id="workreport"
onsubmit="new Ajax.Updater({success:'workshowDiv',failure:'rightWorkSpace'}, '#springUrl("${HuiYee.spaceContextUri}")emr/report/generalx.html',{asynchronous:true, parameters:Form.serialize(this)});return false;"><table width="100%" cellpadding="0" border="0">
<tr>
<td align="center">
起始日期:&nbsp;&nbsp;
<input class="input_txt" type="text" id="startDate" name="sdate" value="#if($queryObj.startDate)$!date.format('yyyy-MM-dd',$!{queryObj.startDate})#end" onfocus="showCalendar('',this,this,'$!{in}','holder',0,10,1)" msg="日期格式不正确" dataType="Date" require="false">
&nbsp;&nbsp;截止至&nbsp;&nbsp;
<input class="input_txt" type="text" id="endDate" name="edate" value="#if($queryObj.endDate)$!date.format('yyyy-MM-dd',$!{queryObj.endDate})#end" onfocus="showCalendar('',this,this,'$!{in}','holder',0,10,1)" msg="日期格式不正确" dataType="Date" require="false">
</td>
</tr>
<tr><td></td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" onclick="alert(document.getElementById('startDate').value)" value=" 查 询 " class="huiyeeBtn"/> &nbsp;&nbsp;&nbsp;
#set ($myowner = $!HuiYee.getBusiness().id)
#if ($myowner)
<input type="button" class="huiyeeBtn" value=" 报 表 " onClick="params=encodeURIComponent(Form.serialize(workreport)+'&owner='+'$myowner');new Ajax.Updater('reporteditView', '#springUrl("${HuiYee.spaceContextUri}reportdownload/report/edt.html?handler=ERN&params=")'+params,{method:'get',asynchronous:true,evalScripts:true});effect_1 = showForm(event,'reporteditView',[]);return false;">
#end
</td>
</tr>
</table>
</form>
要求加个onclick事件判断两个时间不超过3个月.超过不予提交到后台,并给个alt提示下..对js实在是很陌生..求教大神们给想想办法啊....

解决方案 »

  1.   

    js有个onkeyup的事件,可以在案件敲起的时候出发,只要知道alt对应的asi值,就可以写触发实践了
    另外两个实践判断小于3个月,可以用js的date对象的来解决
    加设alt键的ascii的值为100
    winodow.onkeyup = function(){
       if(event.keyCode == 100){
           alert("你按了alt按键")
       }
    }
    var date1 = new Date(2011,11,12);
    var date2 = new Date(2011,10,12);
    var month1 = date1.getMonth();
    var month2 = date2.getMonth();
    alert(month1 - month2)