<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>javascript</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="布尔教育 http://www.itbool.com" /> </head> <body> <script> var stt = 'helloworld'; console.log(stt.length); //获取变量值长度 console.log(stt.substr(3,3)); //从第三个开始截取,截取三个字符 //split 传参 分成一个数组 var arr = [' 春','夏','秋','冬']; console.log(arr.join(',')); //春,夏,秋,冬 逗号隔开 var dou = '东,南,西,北'; console.log(dou.split(',')); // ["东", "南", "西", "北"] //indexOf返回字符串位置 var str = 'douyuanjun'; //console.log(str.indexOf('dou') ? 'find' : 'not find'); //显示not find 不对 //console.log(str.indexOf('miao') ? 'find' : 'not find'); //显示find 不对 console.log(str.indexOf('dou') >=0 ? 'find' : 'not find'); //返回字符串位置,如没找到返回-1(真), 找到返回0(假), 加判断!!! //getFullYear() 返回年份 //getFullYear() var dt = new Date(); console.log(dt.getFullYear()); //返回年份 console.log(Math.floor(2.3)); //2 console.log(Math.random()); // 取随机数[0,1) console.log(Math.random()*5+5); //取随机数[5,10) </script> </body> </html>

我的微信
这是我的微信扫一扫