nodebook/20191103/test.html
2019-11-03 13:08:13 +08:00

42 lines
1016 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
div {
height: 200px;
width: 200px;
background: #10aeff;
}
</style>
</head>
<body>
<input type="button" value="点击" id="btn">
<div id="dv"></div>
<script type="text/javascript">
function my$(id) {
return document.getElementById(id)
}
window.onload = function() {
var btn = my$('btn')
var dv = my$('dv')
function getStyle(ele,attr) {
return window.getComputedStyle ? window.getComputedStyle(ele,null)[attr]:ele.currentStyle[attr]
}
btn.onclick = function() {
console.log(getStyle(dv,'left'))
console.log(getStyle(dv,'margin-left'))
console.log(getStyle(dv,'background'))
console.log(getStyle(dv,'width'))
}
}
</script>
</body>
</html>