How to randomly select one of the list by clicking the button

clipboard.png

< H2 > as shown in the figure, how to click the button to randomly select one of the rows < / H2 >
Mar.23,2021

Math.floor ((Math.random () * arr.length)) do the specific DOM operations yourself


you need to use the random method of the built-in object Math in js

var num = Math.floor(Math.random() * 10)

Math.random () * 10, and using floor () to round down, you can randomly get the 10 numbers of 0,9, that is, the subscript of these p elements in your diagram. Then you can get the corresponding p element according to the subscript and then manipulate the DOM.

Menu