JavaScript randomly adds a picture from the first Dom to the second Div, which is a simple example of five images in the first div that extract the random two to display into the second Div.
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> randomly show five pictures inside two pictures-test picture with Baidu space picture </title>
<script type= "Text/javascript" >
Window.onload = function () {
var count=4;
var original=new array;//Original Array
var tpdiv = document.getElementById (' Kstupian '); Get DOM Objects
var images = tpdiv.getelementsbytagname ("img");
for (Var i=0;i<count;i++) {original[i]=i}
Original.sort (function () {return 0.5-math.random ();});
var mydiv = document.getElementById (' mydiv '); Get DOM Objects
for (Var i=0;i<2;i++) {
var bigimg = document.createelement ("img"); Create an IMG element
Bigimg.width= "200"; 200 pixels without px
Bigimg.src=images.item (Original[i]). src; Assign values to the SRC attribute of an IMG element
Mydiv.appendchild (BIGIMG); Adding child elements to the DOM img
}
};
</script>
<body>
<div id= "Kstupian" >
</div>
<div id= "Mydiv" ></div>
</body>