我想将系统设置的信息都放到一个js文件中,后台来生成这个文件,然后在程序前台引用js中的变量,请问各位,这样该怎样实现?

解决方案 »

  1.   

    你可以象HTML那样,在前台把包含这个JS的语句写出来啊。<script src="/Expert/style/get_css.js"></script>然后就可以调用这个js里面的东西了
      

  2.   

    象这样<%public string abc=js中的变量;%>呢?
      

  3.   

    一般使用 Html服务控件 使用Js和.net语言访问都是可以的
    比如<input id="toTime" readOnly type="text" size="10" name="toTime" runat="server">
    但是这两者语言是不能直接交互的
    我遇到这种情况处理方法是
    使用一个Html服务控件,如果C#要访问js的变量
    那么先把js的这个变量的值传给Html服务控件,
    然后C#在读取这个控件的值现在好像只有这个方法能解决实例代码:
    //声名控件
    <input id="toTime" readOnly type="text" size="10" name="toTime" runat="server">
    // C# 访问,赋值给Html服务控件
    ExamLibrarySystem e=new ExamLibrarySystem();
        int examTime=0;
    int questionCount=0;

    DataTable t=e.GetExam( cat,arr,ref examTime,ref questionCount);
    Session["ExamTable"]=t;
    this.ExamGrid.DataSource=t;
    this.ExamGrid.DataBind();
    this.toTime.Value=examTime.ToString();
    //js读取值,然后处理
     //
           // setExamTime
           //
           start=new Date();
               //document.Form1.toTime.value是字符类型,需要转换成整形值
               var examTime=parseInt(document.Form1.toTime.value,10);
               
           function setExamTime()
           {
           //
           //startTime
           //
               var Time="";
               var h=start.getHours();
               Time=h+":";
               
               var m=start.getMinutes()
               if(m<10)
                   Time=Time+"0"+m+":";
               else
                   Time+=m+":";
               
               var s=start.getSeconds();
                   if(s<10)
                   Time=Time+"0"+s;
               else
                   Time+=s;
               
               document.Form1.startTime.value=Time;
               //这句话不能加,不知道为什么
              //document.Form1.toTime.value="分钟";
               //
               // endTime
               //
               if(examTime+m>=60)
               {
                  
                   if(h==24)
                       h=1;
                   else
                       h+=1;
                   m=examTime+m-60;
               }
               else
               {
                   m=examTime+m
               }
               //
               Time=h+":";
               if(m<10)
                   Time+="0"+m+":";
               else
                   Time+=m+":";
               if(s<10)
                   Time+="0"+s;
               else
                   Time+=s;
               document.Form1.endTime.value=Time;
               //
               //
               //
               go();
           }