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

How to use JS compatibility

php中世界最好的语言
Release: 2018-04-19 10:25:22
Original
1300 people have browsed it

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浏览器
}
Copy after login

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];
 }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template