原始代码如下,我想把:[数字],theURLs,theTitles,还有"http://localhost/... ..."先放进数据库里,然后再调出来,放进JS里。这样的代码怎么写?
PS:还要考虑到安全,不要把数据库连接的密码直接放在外面。(function() {
    var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom,
        lang  = YAHOO.lang,
        slider, 
        bg="slider-bg", thumb="slider-thumb", 
        valuearea="slider-value", textfield="slider-converted-value"
        contentarea="the-content"            // The slider can move 0 pixels up
    var topConstraint = 0;    // The slider can move 200 pixels down
    var bottomConstraint = 200;    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 0.5;    // The amount the slider moves when the value is changed with the arrow
    // keys
    var keyIncrement = 40;    var tickSize = 40;    var maxPosts = 104;    var theURLs = new Array();
    theURLs[0] = "";
    theURLs[1] = "http://localhost/2007/05/";
    theURLs[2] = "http://localhost/2007/06/";
    theURLs[3] = "http://localhost/2007/07/";
    theURLs[4] = "http://localhost/2007/08/";
    theURLs[5] = "http://localhost/2007/09/";
    theURLs[6] = "http://localhost/2007/10/";
    theURLs[7] = "http://localhost/2007/11/";
    theURLs[8] = "http://localhost/2007/12/";
    theURLs[9] = "http://localhost/2008/01/";
    theURLs[10] = "http://localhost/2008/02/";
    theURLs[11] = "http://localhost/2008/03/";
    theURLs[12] = "http://localhost/2008/04/";
    theURLs[13] = "http://localhost/2008/05/";
    theURLs[14] = "http://localhost/2008/06/";
    theURLs[15] = "http://localhost/2008/07/";
    theURLs[16] = "http://localhost/2008/08/";
/*代码过长,省略后面17到103行*/    var theTitles = new Array();
    theTitles[0] = "";
    theTitles[1] = "2007/05";
    theTitles[2] = "2007/06";
    theTitles[3] = "2007/07";
    theTitles[4] = "2007/08";
    theTitles[5] = "2007/09";
    theTitles[6] = "2007/10";
    theTitles[7] = "2007/11";
    theTitles[8] = "2007/12";
    theTitles[9] = "2008/01";
    theTitles[10] = "2008/02";
    theTitles[11] = "2008/03";
    theTitles[12] = "2008/04";
    theTitles[13] = "2008/05";
    theTitles[14] = "2008/06";
    theTitles[15] = "2008/07";
    theTitles[16] = "2008/08";
/*代码过长,后面省略17到103行*/    Event.onDOMReady(function() {        slider = YAHOO.widget.Slider.getHorizSlider(bg, 
                         thumb, topConstraint, bottomConstraint, 10);        slider.getRealValue = function() {
            return Math.round(this.getValue() * scaleFactor);
        }        slider.subscribe("change", function(offsetFromStart) {            var valnode = Dom.get(valuearea);
            var fld = Dom.get(textfield);            // Display the pixel value of the control
            valnode.innerHTML = offsetFromStart;            // use the scale factor to convert the pixel offset into a real
            // value
            var actualValue = slider.getRealValue();            // update the text box with the actual value
            fld.value = actualValue;            // Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg).title = "slider value = " + actualValue;
        });        // slider.subscribe("slideEnd", function() { 
        //   alert("slideEnd"); 
        // });         slider.subscribe("slideStart", function() {
                YAHOO.log("slideStart fired", "warn");
            });        slider.subscribe("slideEnd", function() {
                 YAHOO.log("slideEnd fired", "warn");
                 var endvalue = Dom.get(contentarea);
                 var i = slider.getRealValue();
                 if (i == 0) i = 1;
                 if (i > 90) i = 90;
                 endvalue.innerHTML = '';
                 for (j = 0; j < 10; j++) 
                 {
                   if ((i+j) < maxPosts) {
                     // This doesn't seem to work unless it's all on one line.
                     endvalue.innerHTML += '<a class="rt" href="' + theURLs[i+j] + '" target="_blank">' + theTitles[i+j] + '</a><br>';
                   }
                 }
           });        // Listen for keystrokes on the form field that displays the
        // control's value.  While not provided by default, having a
        // form field with the slider is a good way to help keep your
        // application accessible.
        Event.on(textfield, "keydown", function(e) {            // set the value when the 'return' key is detected
            if (Event.getCharCode(e) === 13) {
                var v = parseFloat(this.value, 10);
                v = (lang.isNumber(v)) ? v : 0;                // convert the real value into a pixel offset
                slider.setValue(Math.round(v/scaleFactor));
            }
        });
        
        // Use setValue to reset the value to white:
        Event.on("putval", "click", function(e) {
            slider.setValue(100, false); //false here means to animate if possible
        });
        
        // Use the "get" method to get the current offset from the slider's start
        // position in pixels.  By applying the scale factor, we can translate this
        // into a "real value
        Event.on("getval", "click", function(e) {
            YAHOO.log("Current value: "   + slider.getValue() + "\n" + 
                      "Converted value: " + slider.getRealValue(), "info", "example"); 
        });
    });
})();

解决方案 »

  1.   

    通过AJAX把数据传后台再存 用到的时候再用AJAX调出来 
      

  2.   

    上面的url数组和title数组可以放到数据库中存入,然后用ajax读取。如果不会ajax建议jquery库,这个较简单
      

  3.   

    弱弱的问一下楼上的,用jquery的话,是否还需要jquery-min.js文件?我已经使用了Yahoo YUI的N个JS文件了,再叠加jquery的话,会不会严重影响页面加载速度……
    如果可以的话,求一段AJAX代码吧~~
      

  4.   

    使用Jquery,jquery-min.js这个是必须的,你可以参考
    http://blog.csdn.net/wwfgu00ing/archive/2010/07/08/5721175.aspx