潤乾填報表定時提交
需求:
在使用填報表的時候,會遇到讓填報表定時提交的需求。比如填報表用於考試時,當到達考試時間後是不允許考試人繼續作答的,因此由系統自動控制提交是不可缺少的。
另外,答題提交後還需跳轉到其他頁面,如等待出成績的日期,注意事項等。
分析來看
涉及兩個方面的問題:1、填報表自動提交;2、提交後可支援跳轉到其他頁面。
以下內容,潤乾填報表的具體實現:
注:這裡填報表就不再設計了,可參考相關教程來實現。
針對問題1:可以定義js定時器,結合潤乾填報表的提交函式,由系統完成提交動作。具體為:
<%
longcurrent_time=System.currentTimeMillis();
longend_time=0;
longtime=1800000;
%>
<script>
var second = <%= time / 1000%>; // 剩餘秒數
var s;
var mi;
// 寫一個方法,將秒數專為天數
var toDays = function(){
s =second % 60; // 秒
mi= (second - s) / 60 % 60; // 分鐘
varh = ((second - s) / 60 - mi ) / 60 % 24; // 小時
vard = (((second - s) / 60 - mi ) / 60 - h ) / 24 // 天
return "剩餘:"+ d + "天" + h + "小時" + mi + "分鐘" + s + "秒";
}
//然後寫一個定時器
window.setInterval(function(){
second --;
document.getElementById("showTimes").innerHTML= toDays ();
if(s==0 &&mi==0){clearInterval(sub_input1());}
}, 1000);
function sub_input1(){
//當計數器到零時,由_inputSubmit 完成自動提交
document.getElementById("showTimes").innerHTML="00秒";
_inputSubmit('<%=sgid%>');
}
</script>
針對問題2:潤乾有實現對提交後儲存成功的動作監聽,可以通過重寫js方法的方式來實現,具體方式為:
<scriptlanguage="javascript">
//固定的方法,當填報表儲存成功後回撥
var inputApi = {};
inputApi.saveSuccess= function(){
alert("儲存成功!");
//呼叫自己的方法處理自己的需求,如此處是關閉當前頁,併兼容所有瀏覽器。如果要實現到其他地址的跳轉,直接通過js實現即可。
closeWebPage();
}
function closeWebPage(){
if(navigator.userAgent.indexOf("MSIE") > 0) {//close IE
if(navigator.userAgent.indexOf("MSIE 6.0") > 0) {
window.opener = null;
window.close();
}else {
window.open('', '_top');
window.top.close();
}
}
elseif (navigator.userAgent.indexOf("Firefox") > 0) {//closefirefox
window.location.href = 'about:blank ';
}else if(navigator.userAgent.indexOf("Chrome") > 0) {//close chrome
window.location.href = 'about:blank ';
}else {//close chrome;It is effective when it is only one.
window.opener = null;
window.open('', '_self');
window.close();
}
}
</script>