可以在搜索按钮添加onclick事件
beginCreateDate等为ID
<script type="text/javascript">
function cx(){
if(document.all.beginCreateDate.value == ""&&document.all.endCreateDate.value == ""){}else{
if(document.all.beginCreateDate.value == ""){
var dqDate = new Date();
document.all.beginCreateDate.value = ymd(dqDate);
}
if(document.all.endCreateDate.value == ""){
var dqDate = new Date();
document.all.endCreateDate.value = ymd(dqDate);
}
if(document.all.endCreateDate.value == document.all.beginCreateDate.value){
var datelist = document.all.beginCreateDate.value.split("-");
var date = new Date(datelist);
var nd = new Date((date/1000+86400)*1000);
document.all.endCreateDate.value = ymd(nd);
}
}
}
function ymd(date){
var Year = 0 ;
var Month = 0 ;
var Day = 0 ;
var CurrentDate = "" ;
// 初始化时间
Year = date.getFullYear();
Month = date . getMonth ()+ 1 ;
Day = date . getDate ();
CurrentDate = Year + "-" ;
if ( Month >= 10 )
{
CurrentDate = CurrentDate + Month + "-" ;
}
else
{
CurrentDate = CurrentDate + "0" + Month + "-" ;
}
if ( Day >= 10 )
{
CurrentDate = CurrentDate + Day ;
}
else
{
CurrentDate = CurrentDate + "0" + Day ;
}
return CurrentDate;
}
</script>
如果单纯使前后日期一致可搜索当天信息,可以在两个日期框上添加onchange
<script type="text/javascript">
function chaxunriqi(){
if(document.all.endApplyDate.value == document.all.beginApplyDate.value){
/* document.all.endApplyDate.value = document.all.beginApplyDate.value + 1; */
var datelist = document.all.beginApplyDate.value.split("-");
var date = new Date(datelist);
var nd = new Date((date/1000+86400)*1000);
/* document.all.endApplyDate.value = nd.getYear()+"-"+nd.getMonth()+"-"+nd.getDate(); */
var Year = 0 ;
var Month = 0 ;
var Day = 0 ;
var CurrentDate = "" ;
// 初始化时间
Year = nd.getFullYear();
Month = nd . getMonth ()+ 1 ;
Day = nd . getDate ();
CurrentDate = Year + "-" ;
if ( Month >= 10 )
{
CurrentDate = CurrentDate + Month + "-" ;
}
else
{
CurrentDate = CurrentDate + "0" + Month + "-" ;
}
if ( Day >= 10 )
{
CurrentDate = CurrentDate + Day ;
}
else
{
CurrentDate = CurrentDate + "0" + Day ;
}
document.all.endApplyDate.value = CurrentDate;
}
}
</script>