我在做一个首页切换的flash动画,但是那些图片需要后台管理的,都写在了js文件里 :
imgUrl1="images/01.jpg";
imgtext1="蔬菜广告创意01"
imgLink1=escape("#");
imgUrl2="images/02.jpg";
imgtext2="蔬菜广告创意02"
imgLink2=escape("#");
imgUrl3="images/03.jpg";
imgtext3="蔬菜广告创意03"
imgLink3=escape("#");
imgUrl4="images/04.jpg";
imgtext4="蔬菜广告创意04"
imgLink4=escape("#");
imgUrl5="images/05.jpg";
imgtext5="蔬菜广告创意05"
imgLink5=escape("#");
 
怎样读取把这些图片做成动态的 ,从数据库里读取,帮忙啊,感激不尽~~~

解决方案 »

  1.   

    你可以把整个代码放在后台输出,用response.write("  "),输出到前台.
      

  2.   

    按照ASP的思路就是定义一个全局变量。后台拼出来后。
    前台用<%=%>来引用。
      

  3.   

    在后台写个方法获取图片路径,然后Response.write("")或者ClientScript.RegisterClientScriptBlock(this,this.GetType(),"url","拼凑的js字符串",true);输出到前台
      

  4.   

    imgUrl1="<%= img1%>";
      

  5.   

    譬如从后台读取数据,得到
    string img1="....";前台JS代码改为
    var imgUrl1="<%= img1%>";
    即可
      

  6.   

    //变量的定义
    var xmlHttp, url//读取数据的文件的路径, xml;
    var txtUser, txtAge, rbtM, rbtF, txtPwd, txtSfzhm, txtDz, txtLxdh, txtEmail, txtGrant, userid, typeID;
    var oldUser, oldSfzhm, selSf;function CreateXMLHttpRequest() {//创建AJAX对象
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
    }
     function sendRequest(urlString, queryString, method, callback) {//判断是GET还是POST
         CreateXMLHttpRequest();
         xmlHttp.onreadystatechange = callback;
         if (method == "GET") {
             xmlHttp.open(method, urlString + escape(queryString) + "&time=" + new Date().getDate(), true);
             xmlHttp.send(null);
         } else {
         xmlHttp.open(method, urlString, true);
             xmlHttp.setRequestheader("Content-Type", "application/x-www-form-urlencoded");
             xmlHttp.send(queryString);
         }
     }
    function updateUser() {//这是按钮CLICK时执行的方法
        initVars();
        xml = createXML();
        url = "../../ashxs/UserHandler.ashx?type=" + typeID.value;
        sendRequest(url, xml, "POST", updateCallback);
    }
    function updateCallback() {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                alert(xmlHttp.responseText);//测试
                  ......//用JS的DOC技术对数据库回来的数据进行处理,你会的吧
            }
        }
    }
    function initVars() {
        txtUser = document.getElementById("txtUser");
        txtAge = document.getElementById("txtAge");
        txtDz = document.getElementById("txtDz");
        txtGrant = document.getElementById("txtGrant");
        txtLxdh = document.getElementById("txtLxdh");
        txtEmail = document.getElementById("txtEmail");
        txtPwd = document.getElementById("txtPwd");
        txtSfzhm = document.getElementById("txtSfzhm");
        selSf = document.getElementById("selSf");
        userid = document.getElementById("userid");
        typeID = document.getElementById("typeID");
        rbtM = document.getElementById("rbtM");
        rbtF = document.getElementById("rbtF");
        oldSfzhm = document.getElementById("oldSfzhm");
        oldUser = document.getElementById("oldUser");
    }不知够不够详细.
      

  7.   

    imgUrl1="images/01.jpg";
    imgtext1="蔬菜广告创意01"
    imgLink1=escape("#");
    imgUrl2="images/02.jpg";
    imgtext2="蔬菜广告创意02"
    imgLink2=escape("#");
    imgUrl3="images/03.jpg";
    imgtext3="蔬菜广告创意03"
    imgLink3=escape("#");
    imgUrl4="images/04.jpg";
    imgtext4="蔬菜广告创意04"
    imgLink4=escape("#");
    imgUrl5="images/05.jpg";
    imgtext5="蔬菜广告创意05"
    imgLink5=escape("#");
     var focus_width=425
     var focus_height=227
     var text_height=18
     var swf_height = focus_height+text_height
     
     var pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4+"|"+imgUrl5
     var links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4+"|"+imgLink5
     var texts=imgtext1+"|"+imgtext2+"|"+imgtext3+"|"+imgtext4+"|"+imgtext5
     
     document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
     document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="images/focus1.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
     document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
     document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
     document.write('</object>');这是我前台显示的图片切换的js代码 ,怎样循环显示后台添加的图片呢
      

  8.   

    在后台写个方法获取图片路径,然后Response.write("")或者ClientScript.RegisterClientScriptBlock(this,this.GetType(),"url","拼凑的js字符串",true);输出到前台 
     
      

  9.   


    例如前台html
    imgUrl1="<%= imgUrl1%>"CS: public string imgUrl1 = "1.jpg";其他一样处理就可以了。
      

  10.   

     var pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4+"|"+imgUrl5
     var links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4+"|"+imgLink5
     var texts=imgtext1+"|"+imgtext2+"|"+imgtext3+"|"+imgtext4+"|"+imgtext5那这里该如如何循环呢,还有点击图片的链接
      

  11.   

    bacstr结合XML实现切换,修改XML
    JS通过AJAX xmlhttp获取数据,或<%= %>