js判断当前浏览器运行环境是google还是IE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button type="button" id="btn1">buttion1</button>
<button type="button" id="btn2">buttion2</button>
<div id="box" style="background-color: antiquewhite;"></div>
<ul id="ul1">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
<script type="text/javascript">
window.onload=function(){
var btn1=document.getElementById("btn1");
var box=document.getElementById("box");
var oUl = document.getElementById("box");
btn1.onclick=function(){
if (oUl.firstElementChild) {
//谷歌浏览器
oUl.firstElementChild.style.background = "red";
alert(getComputedStyle(box,null).backgroundColor)
}
if (oUl.firstChild) {
//IE 浏览器
oUl.firstChild.style.background = "red";
alert(box.currentStyle.backgroundColor)
}
}
}
</script>
</html>
js判断当前浏览器运行环境是google还是IE
最新推荐文章于 2024-04-26 09:24:31 发布