有2个问题劳烦大家帮忙
第一个
RadioButtonList rblDanxuan = new RadioButtonList();//后台生成radiobuttonlist
rblDanxuan.Attributes.Add("onclick", "changeColor('rbtnList" + num.ToString() + "')");//添加onclick事件//JS changeColor方法/
//其实这个是生成试题,然后选中的试题变色,然后统计,已经答了多少题,未答多少题
//现在除了问题,比如说第一个题,你点了一下,已答1题,剩余69,然后在点第二题,已答2题,剩余68,然后再回头点一题,变成已答3,剩余67,下面的js代码我已经做了筛选了,为什么还能重复添加var rblList=new Array();
function changeColor(rblID)
{
    document.getElementById(rblID).style.backgroundColor="#DDF4DF";
    var a =false;
    if(rblList.length==0)
    {
        rblList.push(rblID);
    }
    else
    {
        for(var i=0;i<rblList.length;i++)
        {
            if(rblList[i]==rblID)
            {
                a= false;
            }
            else
            {
                a= true;//查询所点击的radiobuttonlist不在数组中
            }
        }
        if(a)
        {
            rblList.push(rblID);
        }
    }
    document.getElementById('spanRemain').innerHTML="已答:"+rblList.length+"剩余:"+(70-rblList.length);
}
问题二,比较简单,就是一个计时器,js做的考试时间60分钟,到时间自动交卷,已经做好了,问题是不能刷新,一刷新就又变成60分钟了,请教下这个有什么办法解决
下面是代码...var count=60;
function serverCurrTime() {
var str="";
if(count%60!=0){
var temp=count/60+"";
temp=temp.split(".");
str="0"+temp[0]+":"+((count%60-1)>9?count%60-1+"":"0"+(count%60-1))+":"+"59";
}else{
str="0"+((count/60>1)?(count/60-1):0)+":"+59+":"+"59";

document.getElementById("currTime").innerHTML = str;
setTimeout(reduceOneSec,1000);
}function reduceOneSec() {//自动减少一秒
var currTime=document.getElementById("currTime");
// alert(currTime.innerHTML);
var tempTime=currTime.innerHTML.split(":");
var hour=tempTime[0];
var minute=tempTime[1];
var second=tempTime[2];
//alert(hour+":"+minute+":"+second);
if(second>=1){
second=(second-1>9)?(second-1):"0"+(second-1);
}else{
second="59";
if(minute>=1){
minute=(minute-1>9)?(minute-1):"0"+(minute-1);
}else{ 
if(hour>=1){ 
minute="59"; 
hour=(hour-1>9)?(hour-1):"0"+(hour-1);
alert(hour+":"+minute) ;
}else{
minute="00";
hour="0"+0;
}
}
}
document.getElementById("currTime").innerHTML=hour+":"+minute+":"+second;
if(hour==0&&minute==0&&second==0){
qiangzhi();
}else{
setTimeout(reduceOneSec,1000);
}
}function qiangzhi()//强制交卷
{
    document.all.ly.style.display="block";
    document.all.ly.style.width=document.body.clientWidth;
    document.all.ly.style.height=document.body.clientHeight;
    document.getElementById('divQz').style.display="block";
    if(qztime==0)
    {
        document.getElementById('imgBtnCoerce').click();
    }
    else
    {
        document.getElementById('spqzjj').innerHTML=qztime+"秒";
        setTimeout(qiangzhi,1000);
    }
    qztime--;
}
大家帮忙看看 谢谢

解决方案 »

  1.   

    第二个问题,你可以把试卷放在iframe或者frame里
      

  2.   

    第一个问题中,
    a=false时应该break了,不要再继续循环var rblList=new Array();
    function changeColor(rblID)
    {
        document.getElementById(rblID).style.backgroundColor="#DDF4DF";
        var a =false;
        if(rblList.length==0)
        {
            rblList.push(rblID);
        }
        else
        {
            for(var i=0;i<rblList.length;i++)
            {
                if(rblList[i]==rblID)
                {
                    a= false;
                    break;
                }
                else
                {
                    a= true;//查询所点击的radiobuttonlist不在数组中
                }
            }
            if(a)
            {
                rblList.push(rblID);
            }
        }
        document.getElementById('spanRemain').innerHTML="已答:"+rblList.length+"剩余:"+(70-rblList.length);
    }
      

  3.   

    rblDanxuan.Attributes.Add("onclick", "changeColor('rbtnList" + num.ToString() + "')");我猜想 你不知道 这句的意思
      

  4.   


    这个是可以的,他是在Table上加onclick,可以满足他的需求。没必要在每个小项中添加onclick
      

  5.   

    加个break 好了,只是选不中项也会变色...不知道这个问题好不好解决?
    因为radiobuttonlist 是个table  点旁边的也变色了
    第二个问题,你应该 在其他地方 保存用户开始答题的时间每次的60 秒都是先读取用户开始答题的时间 ,读取到 就和当前时间作差, 没读取到 就是60秒--好这个我试试
      

  6.   

    加个break 好了,只是选不中项也会变色...不知道这个问题好不好解决?
    因为radiobuttonlist 是个table 点旁边的也变色了----------------------------------------------------
    出现这个问题的原因就是rblDanxuan.Attributes.Add("onclick", "changeColor('rbtnList" + num.ToString() + "')");这句的问题因为你需要将 onclick 事件 加在 radio html tag 上而不是 radio 所在的 table 上
      

  7.   


    哦 我明白了  加在items上应该就行...我试试
      

  8.   


    那就循环给ListItem加onclick
      

  9.   

    第二个 你可以屏蔽右键 屏蔽F5 来达到屏蔽刷新的功能:  if (code == "1051" && event.button == 0) {  //屏蔽  鼠标右键
                        return false;                }           
                if (event.keyCode == 116) { //屏蔽   F5
                        event.keyCode = 0;
                        event.returnValue = false;
                    }