的最佳途径前段时间我写了一些快速的jQuery代码来选择和广告随机低于什么是容纳数据的jQuery
$(function() {
var theImages = [ '*****.jpg', '******.jpg', '*****.jpg' ];
var theLinks = [ 'http://www.****.co.uk', 'http://www.****.co.uk', 'http://www.*****.co.uk' ]
var theRandomNumber = Math.round(Math.random() * (theImages.length - 1));
$("#ad1").attr('src','images/' + theImages[theRandomNumber]);
$("a#adL1").attr('href', theLinks[theRandomNumber]);
var theRandomNumber2 = Math.round(Math.random() * (theImages.length - 1));
while (theRandomNumber == theRandomNumber2) {
theRandomNumber2 = Math.round(Math.random() * (theImages.length - 1));
}
$("#ad2").attr('src','images/' + theImages[theRandomNumber2]);
$("a#adL2").attr('href', theLinks[theRandomNumber2]);
});
</script>
我现在有一个网站29个HTML页面的代码。每次广告更改时,我都必须更改每一页。有人可以给出一些建议,以最好和最快捷的方式把参数,我只需要更新一件事。然后所有页面将读取这些参数并知道要显示的内容。
感谢保罗
为什么不将变量添加到您的eac函数中h个HTML元素(即'#ad1','#a#adL1'等) – themanatuf 2013-05-09 13:58:13
jquery方法'.data()'在这里有用吗? – 2013-05-09 13:58:18
'theRandomNumber'的生成不统一。 – 2013-05-09 14:00:10