当前位置:网站首页>Why is it invalid to assign values to offsetwidth and offsetHeight

Why is it invalid to assign values to offsetwidth and offsetHeight

2022-06-23 20:56:00 It workers

This chapter introduces a problem that is easy to occur among beginners , to offsetWidth and offsetHeight Invalid assignment .

Invalid assignment is a correct phenomenon , Because it is a read-only attribute .

The code example is as follows :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Front end tribe </title>
<style type="text/css">
#antzone{
  width:200px;
  height:100px;
  background:#ccc;
}
</style>
<script>
window.onload = function () {
  var antzone = document.getElementById("antzone");
  antzone.offsetHeight = 200;
}
</script>
</head>
<body>
<div id="antzone"></div>
</body>
</html>

because offsetWidth and offsetHeight Is a read-only property , So the assignment failed .

原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112290935396815.html