如何使用 JavaScript 設定定位元素的左側位置?
使用 left 屬性設定定位元素的左側位置,比如按鈕。
示例
可嘗試執行以下程式碼,使用 JavaScript 設定定位元素的左側位置 −
<!DOCTYPE html>
<html>
<head>
<style>
#myID {
position: absolute;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<p>This is Demo Text.</p>
<button type="button" id="myID" onclick="display()">Change Left Position</button>
<script>
function display() {
document.getElementById("myID").style.left = "150px";
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP