幻灯片下方的未定义文本
Undefined text underneath the slideshow
我创建了一个幻灯片,除了幻灯片下方的持久文本"未定义"之外,一切似乎都很好。我怎么可能摆脱它?请参阅下面的代码:
var variableslide = new Array()
//variableslide[x]=["path to image", "OPTIONAL link for image", "OPTIONAL text description (supports HTML tags)"]
variableslide[0] = ["https://farm2.staticflickr.com/1497/25124601229_90604fb064_b.jpg"]
variableslide[1] = ["https://farm2.staticflickr.com/1544/25196538220_755bfa57b8_b.jpg"]
variableslide[2] = ["https://farm2.staticflickr.com/1711/24865434833_8759084fed_k.jpg"]
variableslide[3] = ["https://farm2.staticflickr.com/1709/25373709692_bbbd7d1da8_k.jpg"]
variableslide[4] = ["https://farm2.staticflickr.com/1603/25466014396_475df73d82_b.jpg"]
variableslide[5] = ["https://farm2.staticflickr.com/1556/25373732262_7ce94cecb5_b.jpg"]
variableslide[6] = ["https://farm2.staticflickr.com/1537/25492103585_d2339eee89_b.jpg"]
variableslide[7] = ["https://farm2.staticflickr.com/1529/24861576224_d10ddae157_b.jpg"]
variableslide[8] = ["https://farm2.staticflickr.com/1466/25124597469_d8dec7aeac_b.jpg"]
//configure the below 3 variables to set the dimension/background color of the slideshow
var slidewidth = '1024px' //set to width of LARGEST image in your slideshow
var slideheight = '683px' //set to height of LARGEST iamge in your slideshow, plus any text description
var slidebgcolor = '#ffffff'
//configure the below variable to determine the delay between image rotations (in miliseconds)
var slidedelay = 3000
////Do not edit pass this line////////////////
var ie = document.all
var dom = document.getElementById
for (i = 0; i < variableslide.length; i++) {
var cacheimage = new Image()
cacheimage.src = variableslide[i][0]
}
var currentslide = 0
function rotateimages() {
contentcontainer = '<center>'
if (variableslide[currentslide][1] != "")
contentcontainer += '<a href="' + variableslide[currentslide][1] + '">'
contentcontainer += '<img src="' + variableslide[currentslide][0] + '" border="0" vspace="3">'
if (variableslide[currentslide][1] != "")
contentcontainer += '</a>'
contentcontainer += '</center>'
if (variableslide[currentslide][2] != "")
contentcontainer += variableslide[currentslide][2]
if (document.layers) {
crossrotateobj.document.write(contentcontainer)
crossrotateobj.document.close()
} else if (ie || dom)
crossrotateobj.innerHTML = contentcontainer
if (currentslide == variableslide.length - 1)
currentslide = 0
else
currentslide++
setTimeout("rotateimages()", slidedelay)
}
if (ie || dom)
document.write('<div id="slidedom" style="width:' + slidewidth + ';height:' + slideheight + '; background-color:' + slidebgcolor + '"></div>')
function start_slider() {
crossrotateobj = dom ? document.getElementById("slidedom") : ie ? document.all.slidedom : document.slidensmain.document.slidenssub
if (document.layers)
document.slidensmain.visibility = "show"
rotateimages()
}
if (ie || dom)
start_slider()
else if (document.layers)
window.onload = start_slider
<ilayer id="slidensmain" width=&{slidewidth}; height=&{slideheight}; bgColor=&{slidebgcolor}; visibility=hide>
<layer id="slidenssub" width=&{slidewidth}; left=0 top=0></layer>
</ilayer>
<p align="center"><font face="Arial" size="-2">Free DHTML scripts provided by<br>
<a href="http://www.dynamicdrive.com">Dynamic Drive</a></font>
</p>
variableslide[currentslide]
似乎只有一个元素。您正在尝试获取返回undefined
的variableslide[currentslide][2]
在函数内部rotateimages
删除这些行
if (variableslide[currentslide][2]!="")
contentcontainer+=variableslide[currentslide][2]
要更正代码,您需要检查函数中的值未定义而不是空字符串:
function rotateimages() {
现在,仅更改您可以看到行为的第一个元素适用于:
variableslide[0] = ["https://farm2.staticflickr.com/1497/25124601229_90604fb064_b.jpg", "https://farm2.staticflickr.com/1497/25124601229_90604fb064_b.jpg", "TEXT DESCRIPTION"]
并继续处理其余元素,例如:
variableslide[1] = ["https://farm2.staticflickr.com/1544/25196538220_755bfa57b8_b.jpg"]
因为就像您在代码中编写的那样,它们是可选字段。
我的片段:
var variableslide = new Array()
//variableslide[x]=["path to image", "OPTIONAL link for image", "OPTIONAL text description (supports HTML tags)"]
variableslide[0] = ["https://farm2.staticflickr.com/1497/25124601229_90604fb064_b.jpg", "https://farm2.staticflickr.com/1497/25124601229_90604fb064_b.jpg", "TEXT DESCRIPTION"]
variableslide[1] = ["https://farm2.staticflickr.com/1544/25196538220_755bfa57b8_b.jpg"]
variableslide[2] = ["https://farm2.staticflickr.com/1711/24865434833_8759084fed_k.jpg"]
variableslide[3] = ["https://farm2.staticflickr.com/1709/25373709692_bbbd7d1da8_k.jpg"]
variableslide[4] = ["https://farm2.staticflickr.com/1603/25466014396_475df73d82_b.jpg"]
variableslide[5] = ["https://farm2.staticflickr.com/1556/25373732262_7ce94cecb5_b.jpg"]
variableslide[6] = ["https://farm2.staticflickr.com/1537/25492103585_d2339eee89_b.jpg"]
variableslide[7] = ["https://farm2.staticflickr.com/1529/24861576224_d10ddae157_b.jpg"]
variableslide[8] = ["https://farm2.staticflickr.com/1466/25124597469_d8dec7aeac_b.jpg"]
//configure the below 3 variables to set the dimension/background color of the slideshow
var slidewidth = '1024px' //set to width of LARGEST image in your slideshow
var slideheight = '683px' //set to height of LARGEST iamge in your slideshow, plus any text description
var slidebgcolor = '#ffffff'
//configure the below variable to determine the delay between image rotations (in miliseconds)
var slidedelay = 3000
////Do not edit pass this line////////////////
var ie = document.all
var dom = document.getElementById
for (i = 0; i < variableslide.length; i++) {
var cacheimage = new Image()
cacheimage.src = variableslide[i][0]
}
var currentslide = 0
function rotateimages() {
contentcontainer = '<center>'
if (variableslide[currentslide][1] != undefined)
contentcontainer += '<a href="' + variableslide[currentslide][1] + '">'
contentcontainer += '<img src="' + variableslide[currentslide][0] + '" border="0" vspace="3">'
if (variableslide[currentslide][1] != undefined)
contentcontainer += '</a>'
contentcontainer += '</center>'
if (variableslide[currentslide][2] != undefined)
contentcontainer += variableslide[currentslide][2]
if (document.layers) {
crossrotateobj.document.write(contentcontainer)
crossrotateobj.document.close()
}
else if (ie || dom)
crossrotateobj.innerHTML = contentcontainer
if (currentslide == variableslide.length - 1)
currentslide = 0
else
currentslide++
setTimeout("rotateimages()", slidedelay)
}
if (ie || dom)
document.write('<div id="slidedom" style="width:' + slidewidth + ';height:' + slideheight + '; background-color:' + slidebgcolor + '"></div>')
function start_slider() {
crossrotateobj = dom ? document.getElementById("slidedom") : ie ? document.all.slidedom : document.slidensmain.document.slidenssub
if (document.layers)
document.slidensmain.visibility = "show"
rotateimages()
}
if (ie || dom)
start_slider()
else if (document.layers)
window.onload = start_slider
相关文章:
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Highcharts工具提示不显示corrosconding文本值,而是显示'未定义'
- 无法读取未定义的属性“替换” - 替换 JS 生成的 HTML 中的文本
- 在文本区域显示未定义的javascript数组
- 文本框的值打印为“未定义”
- Javascript生成的文本框值=未定义
- 未捕获的ReferenceError:未定义文本
- $event未在文本输入的 ng-change 中定义
- 幻灯片下方的未定义文本
- 无法循环访问比较文本值的数组,使用量角器未定义的结果
- NG-model 未定义多种方式无法从文本框获取文本
- 将“未定义”改为文本
- 未定义的响应来自侧边栏小工具中 XHR 的文本
- 文本变为未定义
- D3 - 未捕获的类型错误:无法调用未定义的方法“文本”
- Get-day文本函数返回了未定义的值
- 来自文本框和单选按钮的用户输入在警报中重复,显示未定义
- AngularJS文本框返回未定义的值
- AngularJS中文本区域的未定义值
- parseInt(code)Uncaught ReferenceError:未定义文本