JS 在 javascript 中,一切东西都可以被当作对象。
**1.**控制台换行
shift + 换行
**2.**Math.floor()
math.floor() 是一个用于向下取整的函数,它通常用于将浮点数舍入为最接近但不大于原始值的整数。
**3.**Math.random()
返回[0, 1)随机数
Math.random() * (max - min) + min;
返回[min, max)随机数
4.Math.round()四舍五入
如果参数的小数部分大于 0.5,则舍入到相邻的绝对值更大的整数。
如果参数的小数部分小于 0.5,则舍入到相邻的绝对值更小的整数。
如果参数的小数部分恰好等于 0.5,则舍入到相邻的在正无穷(+∞)方向上的整数。
注意,与很多其他语言中的round() 函数不同,Math.round() 并不总是舍入到远离 0 的方向(尤其是在负数的小数部分恰好等于 0.5 的情况下)。
5Math.ceil()
静态方法总是向上舍入,并返回大于等于给定数字的最小整数。
6JS操作元素属性
// 获取自定义属性
element.getAttribute('data-color');
//设置
element.setAttribute('src', str);
7localStorage
// An highlighted block
function setUserName(){
let myName = prompt('请输入名字');
if(!myName){
setUserName();
}else{
localStorage.setItem('name', myName);
//ele是元素
ele.textContent = 'Mozilla 酷毙了' + myName;
}
}
//获取
localStorage.getItem('name');
//清除
localStorage.removeItem('name');
//清除所有
localStorage.clear();
8string.slice() 原字符串不变,返回新字符串
参考MDN
const str1 = "The morning is upon us."; // str1 的长度是 23。
const str2 = str1.slice(1, 8);
const str3 = str1.slice(4, -2);
const str4 = str1.slice(12);
const str5 = str1.slice(30);
console.log(str2); // he morn
console.log(str3); // morning is upon u
console.log(str4); // is upon us.
console.log(str5); // ""
console.log(str1); //The morning is upon us.
str1.slice(-3); // 'us.'
str1.slice(-3, -1); // 'us'
str1.slice(0, -1); // 'The morning is upon us'
str1.slice(4, -1); // 'morning is upon us'
终端
**1.**运行项目
在package 中scripts查看脚本 npm run serve
或查看readme
2.
css
1清除浮动
一、父元素的最后一个子元素
<div style="clear: both"></div>
二、父元素上用处多 display: flex;
三、父元素的伪元素
.clearfix::after{
content: " ";
display: table;
clear: both;
}