印象笔记迁移
global对象
var box = '//dog学';var a = encodeURI(box);var b = encodeURIcomponent(box); //%2F%2Fdog%E5%AD%A6alert(a); // //dog%E5%AD%A6alert(b); // %2F%2Fdog%E5%AD%A6alert(decodeURI(a)); // //dog学alert(decodeURIComponent(b)); // //dog学eval('var box = 100');alert(box);eval(alert(100)); //100alert(eval(alert(100))); //100,undefined 第一个打印100,第二个打印eval的返回值eval('function box(){return 123}');alert(box()); //123Math对象
alert(Math.E); //2.718281828459045alert(math.PI); //3.141592653589793alert(Math.min(2,5,8,0)); //0alert(Math.max(2,5,8,0)); //8alert(Math.abs(-5)); //5alert(Math.sqrt(9)); //3
alert(Math.ceil(25.1)); //26alert(Math.ceil(25.5)); //26alert(Math.ceil(25.9)); //26,向上舍入
alert(Math.floor(25.1)); //25alert(Math.floor(25.5)); //25alert(Math.floor(25.9)); //25,向下舍入
3 collapsed lines
alert(Math.round(25.1)); //25alert(Math.round(25.5)); //26alert(Math.round(25.9)); //26,标准的四舍五入Math.random()方法
= Math.floor(Math.random() *总数 + 第一个值)
for (var i = 0; i < 10; i++) { document.write(Math.floor(Math.random() * 10 + 1)); document.write('<br />');} //1-10之间
for (var i = 0; i < 10; i++) { document.write(Math.floor(Math.random() * 6 + 5)); document.write('<br />');} //5-10之间
function select(start, end) { var total = end - start + 1; return Math.floor(Math.random() * total + start);}
4 collapsed lines
for (var i = 0; i < 10; i++) { document.write(select(5, 10)); document.write('<br />');} //5-10之间