Home  >  Article  >  Web Front-end  >  编写针对IE的JS代码两种编写方法_javascript技巧

编写针对IE的JS代码两种编写方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:42:40997browse

有些时候我们需要针对某些IE下的兼容性写单独的JS处理代码。有多种做法:

1.通过检测navigation.userAgent来判断是否是IE,再编写IE分支的处理代码:
2.通过声明@cc_on 语句可以在脚本的注释内启用条件编译功能,这样对于非IE浏览器就会将识别为注释而忽略(实测,这种方式在IE6-9将适用!):

复制代码 代码如下:

/*@cc_on @if (@_jscript)
alert("hello world");
@end @*/
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