01.
<html>
02.
<head>
03.
<title>ThaiCreate.Com jQuery Tutorials</title>
04.
<style>
05.
div, p { width:80px; height:40px; top:0; margin:0;
06.
position:absolute; padding-top:8px; }
07.
p { background:
#fcc; text-align:center; }
08.
div { background:blue; }
09.
</style>
10.
<script type=
"text/javascript"
src=
"jquery-1.6.4.js"
></script>
11.
<script type=
"text/javascript"
>
12.
$(document).ready(
function
(){
13.
14.
var
getPos =
function
(n) {
15.
return
(Math.floor(n) * 90) +
"px"
;
16.
};
17.
$(
"p"
).each(
function
(n) {
18.
var
r = Math.floor(Math.random() * 3);
19.
var
tmp = $(
this
).text();
20.
$(
this
).text($(
"p:eq("
+ r +
")"
).text());
21.
$(
"p:eq("
+ r +
")"
).text(tmp);
22.
$(
this
).css(
"left"
, getPos(n));
23.
});
24.
$(
"div"
).each(
function
(n) {
25.
$(
this
).css(
"left"
, getPos(n));
26.
})
27.
.css(
"cursor"
,
"pointer"
)
28.
.click(
function
() {
29.
$(
this
).fadeTo(250, 0.25,
function
() {
30.
$(
this
).css(
"cursor"
,
""
)
31.
.prev().css({
"font-weight"
:
"bolder"
,
32.
"font-style"
:
"italic"
});
33.
});
34.
});
35.
36.
});
37.
</script>
38.
</head>
39.
<body>
40.
41.
<p>Wrong</p>
42.
<div></div>
43.
<p>Wrong</p>
44.
<div></div>
45.
46.
<p>Right!</p>
47.
<div></div>
48.
49.
</body>
50.
</html>