[英]Selecting random array to print out! How can i print out random array with alle the data including the image? When user clicks on button
Click here点击这里
<script>
var luckBtn = document.getElementById('luck'); //getting the button
//array containing information about different profiles
var randomProfileArray= [
["Jonas", 23, "Væren", "Ja", "images/man1.jpg"], //[0] //first array
["Abdi", 24, "Tyren", "Ja", "images/man2.jpg"], //[1] //second array
["Qais", 27, "Tvillingen", "Ja", "images/man3.jpg"], //[2] //third array
["Lola", 29, "Tyren", "Ja", "images/woman1.jpg"], [3] //fourth array
];
//Array is containing: (Name, age, starsymbol, compatibility, yes, image)//
//I am very beginner in js, but i want to use the math.floor math.random method to print out a random array/profile when user clicks on the button provided in the html. I was wondering how and if i can use the for loop here? //我是js的初学者,但是我想在用户单击html中提供的按钮时使用math.floor math.random方法打印出随机数组/配置文件。我想知道如何以及是否可以使用这里的for循环? And how can i use a function?
我如何使用 function?
</script>
You should use something like that:你应该使用类似的东西:
<button onclick=randomArray()>click on me </button>
and inside script:和内部脚本:
<script>
function randomArray() { // your code here }
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.