残念ながら、私はJSの経験がほとんどないので、しばらくお待ちください:p
サイトでバナーを回転させようとしています。バナーを別の場所に配置し、重複がないようにしたいと考えています。バナーが配列にあると、ローテーションに追加するのが簡単になるので、それも素晴らしいでしょう.
これは、私が機能させようとしてきたコードですが、ほとんど成功していません。メモ帳を介してrotate.jsに保存されています
script type="text/javascript">
link = new Array
image = new Array
link[1]="www.audio-philia.co.uk"
image[1]="www.hificornershop.co.uk/nodups/audiophilia.gif"
link[2]="www.emporiumhifi.com"
image[2]="www.hificornershop.co.uk/nodups/emporiumhifi.gif"
link[3]=""
image[3]=""
link[4]=""
image[4]=""
link[5]=""
image[5]=""
link[6]=""
image[6]=""
link[7]=""
image[7]=""
link[8]=""
image[8]=""
link[9]=""
image[9]=""
link[10]=""
image[10]=""
rnd = (Math.round((Math.random()*9)+1))
document.write('<a href="' + link[rnd] + '" target="_blank">');
document.write('<img src="' + image[rnd] + '" border="0"></a>');
value = array.splice(rnd,1)[0]; // remove the selected number from the array and get it in another variable
logosElement.innerHTML += (value);
}
</script>
次に、バナーを表示する領域に次をコピーします#
<img src='rotate.js?i=0'>image #1
<img src='rotate.js?i=1'>image #2
<img src='rotate.js?i=2'>image #3
等
特定のページのバナー スポットごとに「i」の値が異なる場合、重複はありません。私はphpで非常によく似たスクリプト作業を行っていましたが、これをJSで動作させたいと思っています。