jsp核心代碼:
<table>
<tr>
<td>開始時間</td><td><input type="text" name="start" id="start" value="https://bbs.csdn.net/topics/<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) %>" onclick="main('start')" ></td>
<td>結束時間</td><td><input type="text" name="end" id="end" value="https://bbs.csdn.net/topics/<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) %>" onclick="main('end')"></td>
<td><input type="submit" name="chaxun" value="https://bbs.csdn.net/topics/查詢"></td>
</tr>
</table>
<div id="div1"></div>
<div id="div2"></div>
var now;//當前日期
var allDay = new Array(42); //日期陣列
var n;//當月首日星期數
var days;//當月天數
/**
*獲取當前日期
*/
function getCurrentDate(){
var time=document.getElementById("start").value;
now = new Date(time.substr(0,10));
}
/**
*主函式
*/
function main(str){
var source = str;
getCurrentDate();
var strFrame='<table class=mt id=mt>';
strFrame+='<tr>';
strFrame+='<td>';
strFrame+="<p id=\"prevM\" onclick=\"prevMonth()\">";
strFrame+='<<';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td colspan=5>';
strFrame+='<p>';
strFrame+=now.getFullYear()+'年'+(now.getMonth()+1)+'月';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+="<p id=\"nextM\"onclick=\"nextMonth()\">";
strFrame+='>>';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='</tr>';
strFrame+='<tr>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='日';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='一';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='二';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='三';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='四';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='五';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='<td>';
strFrame+='<p>';
strFrame+='六';
strFrame+='</p>';
strFrame+='</td>';
strFrame+='</tr>';
strFrame+='</table>';
var div1=document.getElementById("div1");
var div2=document.getElementById("div2");
if(source=='end'){
alert("true");
div2.innerHTML=strFrame;
div1.innerHTML="";
}else{
alert("false");
div1.innerHTML=strFrame;
div2.innerHTML="";
}
document.getElementById("prevM").addEventListener("click",prevMonth);
document.getElementById("nextM").addEventListener("click",prevMonth);
}
function prevMonth(){
alert("a");
}
function nextMonth(){
alert("b");
}
運行后只有在div2中可以執行onclick,div1中不能執行,什么原因?哪位高手知道?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/284530.html
標籤:JavaScript
下一篇:新人求助解答
