原始代码如下,我想把:[数字],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");
});
});
})();
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");
});
});
})();
解决方案 »
- 求助:js判断单选按钮选择后提示信息,一直提示函数未定义:(谢谢
- js json处理json字符串
- 让已知id的div上面所有的checkbox 不选中
- onchange 怎么触发不了servlet ?
- 怎么计算JavaScript运行的时间?要可执行代码!
- 如何用javascript实现 焦点到一个TextBox,它就显红色,当焦点离开时,它就显回原来的白色...
- 一个table里面可以一些格有边框,一些格没有边框吗?
- JS或Ajax在浏览器上使用不了
- 请解释一下这个函数
- js 怎么点table <td>的<a herf ="#"> 出现弹窗
- 在html中用js按时间来高亮显示文字
- MF下取不出来图片title属性
如果可以的话,求一段AJAX代码吧~~
http://blog.csdn.net/wwfgu00ing/archive/2010/07/08/5721175.aspx