提交的时候需要些客户端的验证,下面是一个验证的javascript代码
function CheckItem()
{
alchk=0;//用来保存回答题数
for(k=0;k<44;k++)//44表示有44道题目
{
chkc=0;//每题的回答中有几个选中,这里我使用的是checkbox,如果使用radiobottonlist就只能有一个选中
for(j=0;j<4;j++)//4表示每题都有4个选择项
{
strid = 'dlQuestion__ctl'+k+'_dlSelection__ctl'+j+'_ckSelection';//获得选项在页面中的ID
if((document.getElementById(strid)).checked)//如果选中
{
chkc++;
}
}
if(chkc>1)//表示超过一个选项
{
h=k+1;
alert('第'+h+'题答案超过一个!');
return false;
}
if(chkc<1)
{
}
else
{
alchk++;
}
}
if(alchk<44)// alchk<44表示没有答完题目
{
//alert('not finished');
return confirm('您有题目没有完成,是否提交?');
}
return confirm('确定提交吗?');
}
4. 页面中还需要用到一些javascript脚本,如下
<SCRIPT language="JavaScript">
//计时器
function display(){
rtime=etime-ctime;
sstime=1800-rtime;
if (rtime>60)
{
m=parseInt(rtime/60);
}
else{
m=0;
}
if (sstime>=60)
{
m1=parseInt(sstime/60);
}
else{
m1=0;
}
s=parseInt(rtime-m*60);
if(s<10)
s="0"+s
s1=parseInt(sstime-m1*60);
if(s1<10)
s1="0"+s1
document.getElementById('lbLeftMin').innerText=m+":"+s
document.getElementById('lbCostMin').innerText=m1+":"+s1
window.setTimeout("checktime()",1000)
}
function settimes(){
//alert("You have 20 minutes time !")
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
etime=hours*3600+mins*60+secs;
etime+=1800; //You can change the value of 1200 according to how much time you wish to set the timer. Where 1200 is time in secs (1200 = 20 mins * 60 secs/min). Max time is 60 mins (3600secs)
checktime();
noback();
}
function checktime(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
ctime=hours*3600+mins*60+secs
if(ctime>=etime){
expired();
}
else
display();
}
function expired(){
document.getElementById('btnHid').click();//强制提交,btnHid为一个在页面中高度为0,宽度为0的按钮,按钮的事件在.cs文件写好
//alert("Time expired");
//location.href="Main.html"; //或者转到其他的页面
}
//屏蔽鼠标右键
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
//屏蔽 F5 刷新键等键
document.οnkeydοwn=function(){
if(event.keyCode==8||event.keyCode==116||(event.ctrlKey && event.keyCode==116)){
alert("禁止刷新网页!");
event.keyCode=0;
return false;
}
}