如何将图像添加到此随机数组?

时间:2017-11-15 23:02:53

标签: jquery html css codepen

我想知道是否可以将图像添加到随机生成器中,以便当单击按钮时,将显示电影标题和电影中的图片。

BEGIN
SET NOCOUNT ON
DECLARE @name varchar(50)
SET @name = 'bananas'
SELECT category, sum(netweight) AS NetWeight from PieChart group by 
category, name HAVING name LIKE @name
END
function GetValue()
{
    var myarray= new Array("The Santa Claus","Just Friends","Home Alone", "Home Alone 2","Serendipity","Love Actually","Elf","Christmas Vacation","A Christmas Story","The Grinch","Jingle All the Way","Rudolph the Red-Nosed Reindeer","Ernest Saves Christmas","Frosty the Snowman","The Muppet Christmas Carol","The Nightmare Before Christmas","Jesus of Nazareth 1977","Bad Santa");
    var random = myarray[Math.floor(Math.random() * myarray.length)];
    //alert(random);
    document.getElementById("message").innerHTML=random;
}
#btnSearch {
  color: white;
  background-color: green;
  border: none;
  padding: 10px;
  font-family: verdana;
  font-weight: bold; 
  
  }
h1 {
  text-shadow: -2px 0 green, 0 2px green, 2px 0 green, 0 -2px green;
}
body {
  background-image: url("http://www.publicdomainpictures.net/pictures/20000/velka/green-christmas-background.jpg");
}

#generator {
  display: block;
  margin: auto;
  text-align: center;
  background-color: #ff7878; 
  border: solid;
  border-color: red; 
  height: 250px;
  max-height: 250px;
}

.fa-snowflake-o {
  padding: 15px;
  color: white;
  
}

.fa-gift {
  padding: 15px;
  color: #ff0000;
  
}

.fa-tree {
  padding: 15px;
  color: #378b29;
  
}


#message {
  padding-top: 25px;
  padding-bottom: 25px;
  font-family: verdana; 
  font-size: 20px; 
  font-weight: bold; 
}

.spin {
  -webkit-animation: spin 1s infinite linear;
  -moz-animation: spin 1s infinite linear;
  -o-animation: spin 1s infinite linear;
  animation: spin 5s infinite linear;
     -webkit-transform-origin: 50% 58%;
         transform-origin:50% 58%;
         -ms-transform-origin:50% 58%; /* IE 9 */
}

@-moz-keyframes spin {
  from {
    -moz-transform: rotate(0deg);
  }
  to {
    -moz-transform: rotate(360deg);
  }
}

@-webkit-keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

1 个答案:

答案 0 :(得分:0)

只要把它变成一个二维数组,那么这样的东西就可以了。

var arr = [
        ["Movie Name 1", "Picture URL 1"],
        ["Movie Name 2", "Picture URL 2"],
        ["Movie Name 3", "Picture URL 3"],
        ["Movie Name 4", "Picture URL 4"],
        ["Movie Name 5", "Picture URL 5"]
];
var random = myarray[Math.floor(Math.random() * myarray.length)];

document.getElementById("picture").src=random[1];
document.getElementById("message").innerHTML=random[0];