小程序js随机生成字符串

11次阅读

共计 263 个字符,预计需要花费 1 分钟才能阅读完成。

思路:在一个数组中,随机选取某一个字符串,打印到页面中
关键 js
/**
* 随机生成文本
*/
txt_title(){
var that =this;
var say;
var says = [‘ 送您一份知识大礼包,请查收 ’,’ 送您一份小礼物,请查收 ’];
var ran = Math.floor(Math.random() * says.length);
say = says[ran];
that.setData({
nick_title: say,
})

console.log(say); // 可能出现的结果是:1、送您一份知识大礼包,请查收,2 送您一份小礼物,请查收
},

正文完
 0