- CSS:border-top-right-radius="50%";
JS:borderTopRightRadius="50%"; - JS分号处理:写javascript的时候,如果每条语句都独自写成一行,是不需要写分号的,但是下一行如果遇到上面提到的符号,javascript可能会与下一行合并解释。其中以“/”、“+”和“-”开头的语句在实现项目中比较少见,以“(”和“[”开头的则非常常见。如果在return、break、continue、throw等关键字后面换行,javascript会在换行处填补分号。
- (function(){...})() // 自动执行
- document.getElementById(...).onclick=function(){...}
- DOM Ready 和 DOM Load 区别:点击打开链接
- var a=1
console.log(a,a,a,a,a,a,a,a)
Ps:支持多个变量输出。 - 控制台输出:
console.log('8888',8888) // 控制台输出,前黑(字符串)后紫(数值) console.log('8888'+8888,8888) // 88888888 8888 前黑(字符串)后紫(数值) console.log('8888'-888,8888) // 8000 8888 前紫(数值)后紫(数值) // number number string defined boolean object console.log(typeof(123),typeof(NaN),typeof('123'),typeof(c),typeof(1==1),typeof(null))
- this 用法:
while(i<tab.length){ tab[i].index=i // 给 tab[i] 加个属性名称为index,同时赋值为i tab[i].onclick=function(){ var e=0 while(e<tab.length){ tab[e].style.color='#000' con[e].style.display='none' e++ } // 这里不能是 tab[i].style.color='red' 因为 while 一进来就运行了 // 使 i==tab.length,所以这里必须要用 this 指针,指的就是【当前点击的tab[i]】 this.style.color='red' con[this.index].style.display='block' } i++ }
- setInterval(函数,毫秒),clearInterval(变量),setTimeout(函数,毫秒),如:
1) setInterval(function(){...},1000)
2) function fun(){...}
setInterval(fun(),1000) // F,加括号是执行函数的意思,但 setInterval 本身就带有执行函数的功能
setInterval(fun,1000) // T
3) var timer = setInterval(fun,1000)
clearInterval(timer) // 清除定时器
4) setTimeout(function(){...},1000) // 过1s后才执行函数,而setInterval是每隔 N s,执行
Ps:在每次开始 setInterval 前,保险起见先清除下 clearInterval。 - scrollWidth、clientWidth、offsetWidth 区别。点击打开链接
- parseInt(...)、Math.random()
console.log(Math.random()) // [0,1) console.log(parseInt(Math.random()*10)) // [0,9] console.log(parseInt(Math.random()*21)) // [0,20] console.log(parseInt(5+Math.random()*(21-5))) // [5,20] // console.log(a+Math.random()*(b+1-a)) // [a,b] console.log(parseInt("1234asd")) // 1234 console.log(parseInt("1234a56sd")) // 1234
- 待更新...
JS - 基础知识篇
猜你喜欢
转载自blog.csdn.net/dream_weave/article/details/80479268
今日推荐
周排行