Home > Web Front-end > JS Tutorial > js operator example code_javascript skills

js operator example code_javascript skills

WBOY
Release: 2016-05-16 18:43:46
Original
1132 people have browsed it
Copy code The code is as follows:

var $mfunc=function(){
return {
//This function determines the browser type. For simplicity, it returns a numerical representation,
//1.ie6;2.ie7; 3.ie8;4.ie5.5;5, Firefox;6.chrome;7 .Opera;8.Safari;0. Undetectable browser
//Other browsers can add it themselves
whichOS:function(){
var useragent=navigator.userAgent.toLowerCase();
return (/MSIE 6/i.test(useragent)==true&&1)||
(/MSIE 7/i.test(useragent)==true&&2)||
(/MSIE 8/i.test (useragent)==true&&3)||
(/MSIE 5/i.test(useragent)==true&&4)||
(/Firefox/i.test(useragent)==true&&5)||
(/Chrome/i.test(useragent)==true&&6)||
(/Opera/i.test(useragent)==true&&7)||
(/Safari/i.test(useragent)= =true&&8)||0
}
}
}()

Pay attention to the && and ||, the explanations are all in the comments
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