我想只取出动态链接,但不是从这里拿出所有对象:
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="/documents/templates/bilgiteknolojileri/standalone.swf"
myimages[2]="/documents/templates/bilgiteknolojileri/mobil.swf"
myimages[3]="/documents/templates/bilgiteknolojileri/3b2.swf"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<embed wmode="transparent" src="'+myimages[ry]+'" height="253" width="440"></embed>')
}
random_imglink()
我的意思是,像$ random_link $动态链接一样制作smth,这样我就可以把它放在html代码中
<embed wmode="transparent" src="$random_link$" height="253" width="440"></embed>
答案 0 :(得分:0)
我无法弄清楚你在问什么,但是如果你想从函数中获取链接(可能作为返回值)以便远离document.write
(几乎总是一个好主意,远离那个),然后:
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="/documents/templates/bilgiteknolojileri/standalone.swf"
myimages[2]="/documents/templates/bilgiteknolojileri/mobil.swf"
myimages[3]="/documents/templates/bilgiteknolojileri/3b2.swf"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0) {
ry=1;
}
return myimages[ry];
}
alert(random_imglink()); // alerts one of the three paths above
偏离主题:这个功能清理了一些:
function random_imglink(){
//specify random images below. You can have as many as you wish
var myimages = [
"/documents/templates/bilgiteknolojileri/standalone.swf",
"/documents/templates/bilgiteknolojileri/mobil.swf",
"/documents/templates/bilgiteknolojileri/3b2.swf"
];
return myimages[Math.floor(Math.random()*myimages.length)];
}
alert(random_imglink()); // alerts one of the three paths above
的变化:
我没有考虑路径的共同部分,因为假设可能有其他人在以后添加了没有那个共同部分(/documents/templates/bilgiteknolojileri/
)。如果路径始终以此开头,那么显然您可以通过仅列出一次然后附加更改的位来减小脚本的大小。
答案 1 :(得分:0)
function randomItem(theArray) {
return theArray[Math.floor(theArray.length * Math.random())];
}
myImages = ["some","image","paths"];
var theFlashElement = '<embed wmode="transparent" src="' + randomItem(myImages) + '" height="253" width="440"></embed>';
document.getElementById("flashContainerId").innerHTML = theFlashElement;