4 like 0 dislike
1.9k views

Write a JavaScript program to display a random image (clicking on a button) from the following list.
Sample Image information :

"PIPLS width: "240", height: "160"
"PIPLS width: "320", height: "195"
"PIPLS width: "500", height: "343"

[Exercise] Essay (Open question) - asked in 2016-2 CSIEB0270 - Internet System Design and Practice by (18k points)
ID: 23134 - Available when: Unlimited - Due to: Unlimited
| 1.9k views
0 0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test 1</title>
<script>
function changePicture( )
{
var x =Math.floor((Math.random()*3)+1);
var pic1 = document.getElementById("pic1");
var text1 = document.getElementById("text1");
if(x==1)
{
pic1.src ="PIPLS
//pic1.width="240";
//pic1.height: "160" ;
}
else if(x==2)
{
pic1.src ="PIPLS
//pic1.width="320";
//pic1.height: "195" ;
}
else
{
pic1.src ="PIPLS
//pic1.width="500";
//pic1.height: "343" ;
}
text1.innerHTML += x+" " ;
}
</script>
</head>
<body>
<h2> Random picture </h2>
<img id = "pic1">
<br>
<button onclick ="changePicture( )"> click to random choose a picture
</button>
<p id = "text1"> </p>
</body>
</html>

練習的code

16 Answers

0 like 0 dislike
Hidden content!
*** * **** * ** * * ***** *** *** * ** ** **
answered by (-85 points)
0 like 0 dislike
Hidden content!
* ** *** ** ** * ** ****** ** ** ****
answered by (-211 points)
0 like 0 dislike
Hidden content!
var * * = new *
* = * ** * ** * ** ** * ** *** * **
= *
**** * = *
* * * ***
* ** = *
answered by (72 points)
0 like 0 dislike
Hidden content!
** ** * * **** * ** * **** * * * * * * *** **
answered by (16 points)
0 like 0 dislike
Hidden content!
<html>
*** * * * *** * * * * * ** ** ***
***** * ** ** * *** *** * ****** * ** ** ** * ** * *
** * ** **** **** * ** * * **** * *** ** * ** ** *** *** * imgurl = [
** * * ***** *** * ** * * ** ** * *** ****** * ********** * * **** * * * ** * ** * * * * * ** **** * *
*** * * * * *** ** ****** * * *** * * * ***** *** * **** *** * ** **** * *** ** ******** * **** * * ******* *
****** *** * ** * * ** * * ***** *** *** **** ** *** * * * * * ** ****** * * ** ** ** * ** * * * ** * * ** * *
*** * *** ** * * * * **** ****** * ****** ** ** * ***** *** *
***** * * * ** ********** *** * * * * * *** * * * ***** ** *** * * *
** * ** **** *** * **** *** ** ** ** ** ***** ** * * *
* ** * **** * * ** *** * ** **** * * * **** * ** * * * ** * onClick() {
** * ** * *** **** ** * ** * * * * ** *** ***** **** *** * * * ** *** * ***** * ** **** * * imgNumber = Math.floor(Math.random()*3);
*** * * **** *** * ** *** ** ** * * * ** * **** *** * * * ** **** ** *** ** ***** *** ** ** type ="button" onclick="onClick()" value="random img"></input>');
** * ** ** * ***** * ** **** * ** * * * ******** ** * * ******** * ** * ** ** ***** *** * *** *** * **** ** ** * ** = imgurl[imgNumber];
* * *** * *** * * * *** ** * ******** ** ** * **** * ** * * ** **** ** * *** ** ***** ** **** * ** **** src="'+imgurl[imgNumber]+'">');
* * * * ** * *** ** * *** * *** * ** * **** ***** *
***** * ** * ******** *** * **** *

<body>
* ** * ** **** * * * ** * *** * * *** ** ***** *** **** type ="button" onclick="onClick()" value="random img"></input>
* * * * **** * * ** ** *** * **** * * ***** ******* ** name="slideshow" src="">

</body>

</html>
answered by (18 points)
edited by
0 like 0 dislike
Hidden content!
* **** * ***** *** **** * * **** ** * * ** ***** *
answered by (-32 points)
edited by
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.131.141
©2016-2025

Related questions

3 like 0 dislike
17 answers
[Exercise] Essay (Open question) - asked Mar 23, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23133 - Available when: Unlimited - Due to: Unlimited
| 2k views
3 like 0 dislike
18 answers
[Exercise] Multichoice - asked Mar 22, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23127 - Available when: Unlimited - Due to: 2017-03-23 09:30:00
| 1.7k views
2 like 0 dislike
0 answers
[Resource] asked Mar 23, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23132 - Available when: Unlimited - Due to: Unlimited
| 46 views
3 like 0 dislike
18 answers
[Exercise] True/False - asked Mar 22, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23130 - Available when: Unlimited - Due to: 2017-03-23 09:30:00
| 1.9k views
2 like 0 dislike
26 answers
[Exercise] Multichoice - asked Mar 22, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23129 - Available when: Unlimited - Due to: Unlimited
| 2.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users