旋转图像库与文本和链接

时间:2014-02-25 19:23:51

标签: javascript jquery html

我有这个应该工作的JavaScript。我没有看到它在行动,但我希望它的工作原理。 JS应该选择一个随机图像,然后显示属于该图片的文本,这张图片也应该作为另一个页面的链接。

BUT!我做不到!有什么遗漏或我错过了如何在我的网站上实现它?

!! SCRIPT UPDATED !!

我的JS - 我保存在一个单独的文件中:

<script type="text/javascript">
var imagenumber = 10 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;

images = new Array;
images[1] = "img/rot3gal/cash.jpg";
images[2] = "img/rot3gal/carinjo.jpg";
images[3] = "img/rot3gal/casillas.jpg";
images[4] = "img/rot3gal/churchill.tif";
images[5] = "img/rot3gal/colman.jpg";
images[6] = "img/rot3gal/concosmos.jpg";
images[7] = "img/rot3gal/cooper.jpg";
images[8] = "img/rot3gal/corlando.jpg";
images[9] = "img/rot3gal/magicmemphis.jpg";
images[10] = "img/rot3gal/sidney.jpg";
var image = images[rand1];

links = new Array;
links[1] = "http://www.stutteri-volstrup.dk/cash.shtml";
links[2] = "http://www.stutteri-volstrup.dk/carinjo.shtml";
links[3] = "http://www.stutteri-volstrup.dk/casillas.shtml";
links[4] = "http://www.stutteri-volstrup.dk/churchill.shtml";
links[5] = "http://www.stutteri-volstrup.dk/colman.shtml";
links[6] = "http://www.stutteri-volstrup.dk/concosmos.shtm;l"
links[7] = "http://www.stutteri-volstrup.dk/cooper.shtml";
links[8] = "http://www.stutteri-volstrup.dk/corlando.shtml";
links[9] = "http://www.stutteri-volstrup.dk/magicmemphis.shtml";
links[10] = "http://www.stutteri-volstrup.dk/sidney.shtml";
var link = links[rand1];

var Quotation=new Array() ;

Quotation[1] = "Volstrups Cash";
Quotation[2] = "Carinjo DVH 847";
Quotation[3] = "Volstrups Casillas DVH 928";
Quotation[4] = "Churchill EDH 475";
Quotation[5] = "Colman";
Quotation[6] = "Con Cosmos DVH 898";
Quotation[7] = "Blejsbjergs Cooper DVH 874";
Quotation[8] = "Corlando EDH 476";
Quotation[9] = "Magic Memphis";
Quotation[10] = "Sidney DH 412";

var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){ return Quotation[whichQuotation];}
</script>

我用什么来获取图像和链接:

<script language="JavaScript" type="text/JavaScript">
document.write('<A HREF="' + link + '"><IMG SRC="' + image + '" alt="' + showQuotation() + '" border="0" width="110" height="90"></a>')
</script>

我用什么来获取报价:

<script language="JavaScript" type="text/JavaScript">
showQuotation();
</script>

希望你们能帮助我,所以我可以让这个脚本工作:)

1 个答案:

答案 0 :(得分:0)

好吧,我看到你的外部js文件中缺少一些分号。控制台说什么?也许最好让你的函数showQuotation()只做

function showQuotation(){ return Quotation[whichQuotation];}