问题描述
点击这里
<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","images/man2.jpg"],//[1] //second array
["Qais",27,"Tvillingen","images/man3.jpg"],//[2] //third array
["Lola",29,"images/woman1.jpg"],[3] //fourth array
];
//Array is containing: (Name,age,starsymbol,compatibility,yes,image)//
///我是js的初学者,但是当用户单击html中提供的按钮时,我想使用math.floor math.random方法打印出随机数组/配置文件。我想知道如何以及是否可以在这里使用for循环?而我该如何使用功能呢?
</script>
解决方法
您应该使用类似的内容:
<button onclick=randomArray()>click on me </button>
和内部脚本:
<script>
function randomArray() { // your code here }
</script>