Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 jQuery 中有一个包含 19 个字段的数组,并且想提醒一个随机字段。我在想一些 Math.rand()?
谢谢!
丹尼斯
懒惰问题的懒惰答案:
alert( arr[(~~(Math.random() * arr.length))] )
就像下面这样使用Math.random,
Math.random
var randomnumber = Math.floor(Math.random()* $('selector').length) // ^--$('selector').length = 19