This time I will bring you how to use JS compatibility. What are the precautions when using JS compatibility? Here are actual cases, let’s take a look.
1.EventBubbling:
//取消冒泡 if(e.stopPropagation){ e.stopPropagation();//w3c定义的APIbiaozhun }else{ e.cancelBubble=true;//兼容IE 6,7,8浏览器 }
2. Get the CSS attribute value of a certain element:
//获取某个元素的CSS属性值 function getStyle(element,stylename){ if(element.currentStyle){ //IE return element.currentStyle[stylename]; }else{ //其他浏览器 var computedStyle=window.getComputedStyle(element,null); return computedStyle[stylename]; } }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
js implements uniform fade-in and fade-out of images
Detailed explanation of the use of Vue scope slots
JS implements data validation and check box form submission
The above is the detailed content of How to use JS compatibility. For more information, please follow other related articles on the PHP Chinese website!