<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaSrcipt获取HtmlStyle属性兼容方法</title>
<style>
body { padding:10px;}
* { margin:0px; padding:0px;}
#div1 { width:100px; height:100px; background-color:#65DBC7; position:absolute; left:10px; top:50px;}
</style>
<script>
window.onload = function(){
var oBut = document.getElementById('but1');
var oDiv = document.getElementById('div1');
oBut.onclick = function(){
setInterval(function(){
oDiv.style.left = parseInt(getStyle(oDiv,'left')) + 10 + 'px';
},20);
}
//获取style值 兼容所有浏览器的写法,FF,IE // YuqiDai@G
function getStyle(obj,attr){return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj)[attr];}
}
</script>
</head>
<body>
<input type="button" value="按钮" id="but1" />
<div id="div1"></div>
</body>
</html>
JavaSrcipt获取HtmlStyle属性兼容方法
最新推荐文章于 2024-09-20 15:16:38 发布