当前位置: 首页 > Web前端 > HTML5

10点前端知识(2019.5.28)

时间:2023-04-05 18:09:04 HTML5

1.Firefox的mouseenter问题{this.mouseEnter(e,);}}onBlur={()=>{}}onMouseLeave={e=>{this.mouseOut(e,);}}/>onMouseEnter事件在Firefox上会不断触发mouseenter和mouseleave事件,所以需要先设置一个flag=false,在onMouseEnter时设置为true,在onMouseLeave中设置为false,这样不断触发的onMouseEnter事件才能只被触发一次。this.state={flag:false}mouseEnter(){if(!this.state.flag){//...做一些事情this.setState({flag:true,})}}mouseOut(){this.setState({flag:false,})}2.ESLint一元运算符'++'使用i++不安全,所以使用i+=1//badfor(leti=0;i标签自带的transform属性调整svg中标签的位置6.get请求中的参数是中文的,ie11无法识别。使用encodeURI()方法来识别它们,它不会影响其他浏览器。encodeURI(url)7.document.activeElement.tagName返回文档中当前获取的焦点元素console.log(document.activeElement.tagName)(之前记得这个,后来发现工作中很少用到)8.注意写法,赋值的同时判断条件letaletb=1if((a=b)!==2){console.log(a,'a28')//1}9.网上常见的一个JS随机数生成算法如下。为什么要用9301、49297、233280这三个号码做基数?函数rnd(种子){种子=(种子*9301+49297)%233280;//为什么要用这三个数?返回种子/(233280.0);};functionrand(number){today=newDate();种子=今天.getTime();返回Math.ceil(rnd(seed)*number);};myNum=(rand(5));简单来说,有以下三个原因:(1)c和m互质(2)a-1可以被m的所有质因数整除(3)如果m是4的倍数,a-1也一定是a4的倍数。以上三者称为赫尔-多贝尔定理可以看出a=9301,c=49297,m=233280的参数都满足以上三个条件。详见:https://www.zhihu.com/question/2281810410,浏览器类别判断window.navigator.userAgentconsole.log(window.navigator.userAgent,'userAgent67')♂safebrowser:constis360=window.navigator.userAgent.indexOf("WOW64")!==-1Edge:constisEdge=window.navigator.userAgent.indexOf('Edge')!==-1;IE11:constisMs=window.导航器.userAgent.indexOf('.NET')!==-1;(结尾)