JSP的常用程式碼片段
阿新 • • 發佈:2018-11-08
獲取滑鼠位置的程式碼片段
<SCRIPT LANGUAGE="JavaScript"> var x; var y; if (navigator.appName == 'Netscape'){ document.captureEvents(Event.MOUSEMOVE); document.onmousemove = netscapeMouseMove; } function netscapeMouseMove(e) { if (e.screenX != document.test.x.value && e.screenY != document.test.y.value); { x= e.screenX; y= e.screenY; document.test.x.value = e.screenX; document.test.y.value = e.screenY; } } function micro$oftMouseMove() { if (window.event.x != document.test.x.value && window.event.y != document.test.y.value); { x= window.event.x; y= window.event.y; document.test.x.value = window.event.x; document.test.y.value = window.event.y; } } </SCRIPT> <FORM NAME="test"> X: <INPUT TYPE="TEXT" NAME="x" SIZE="4"> Y: <INPUT TYPUE="TEXT" NAME="y" SIZE="4"> </FORM>
自動重新整理程式碼:
<% // 設定每隔5秒重新整理一次 response.setIntHeader("Refresh", 1); // 獲取當前時間 Calendar calendar = new GregorianCalendar(); String am_pm; int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); if(calendar.get(Calendar.AM_PM) == 0) am_pm = "AM"; else am_pm = "PM"; String CT = hour+":"+ minute +":"+ second +" "+ am_pm; out.println("當前時間為: " + CT + "\n"); %>