jQueryを使用して各リンクをクリックするとページの背景をランダムに変更するためのビンを作成しました。したがって、次の手順に従ってください。
1)ヘッダーに最新のJqueryjavaスクリプトファイルを含めます。
2)HTML:
<div>
<p>
When you click on following paragraph link, every time it will be changed random background of the page
</p>
<p>
You have a present that was really memorable. It could have been given for an
<a href="#">
important occasion
</a>
or just for no reason at all. Tell us about the present and why it was memorable. Include the reason it was given, a
<a href="#">
description
</a>
of it, and how you felt when you got it.
The objective is to write a
<a href="#">
narrative essay
</a>
about this present you were given
The subject is a
<a href="#">
memorable present
</a>
The three main subtopics are:
<ul>
<li>
<a href="#">
the reason it was given
</a>
</li>
<li>
<a href="#">
a description of it and
</a>
</li>
<li>
<a href="#">
how you felt when you got it
</a>
</li>
</ul>
</p>
</div>
CSS:
body{
background:url("http://www.freeppt.net/background/modern-pink-floral-backgrounds-for-powerpoint.jpg");
}
JQuery:
var items = new Array();
items[0] = "http://www.publicdomainpictures.net/pictures/10000/nahled/abstract-orange-background-29541280675430Trj9.jpg";
items[1] = "http://www.psdgraphics.com/wp-content/uploads/2011/03/red-flowing-background.jpg";
items[2] = "http://www.dvd-ppt-slideshow.com/images/ppt-background/background-3.jpg";
items[3] = "http://www.purplebackgrounds.net/wp-content/uploads/2011/10/purple-heart-background-680x544.jpg";
items[4] = "http://www.freeppt.net/background/beautiful-on-green-backgrounds-for-powerpoint.jpg";
$(function() {
var bg_img = '',
last_bg = '';
$("a").click(function() {
bg_img = items[Math.floor(Math.random() * items.length)];
if (last_bg == bg_img) bg_img = items[Math.floor(Math.random() * items.length)];
last_bg = bg_img;
$("body").css('backgroundImage', 'url(' + bg_img + ')');
});
});
http://codebins.com/codes/home/4ldqpbcでDEMOをお試しください