Home  >  Article  >  Web Front-end  >  How to use JS compatibility

How to use JS compatibility

php中世界最好的语言
php中世界最好的语言Original
2018-04-19 10:25:221239browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn