คุณสมบัติคำสั่ง HTML DOM Style ส่งคืนและแก้ไขลำดับของไอเท็มแบบยืดหยุ่นที่สัมพันธ์กับรายการแบบยืดหยุ่นที่เหลือภายในคอนเทนเนอร์เดียวกันในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
1. การส่งคืนสินค้า
object.order
2. แก้ไขคำสั่งซื้อ
object.order = “value”
ในที่นี้ ค่าสามารถเป็น −
| ค่า | คำอธิบาย |
|---|---|
| ค่าเริ่มต้น | ตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | รับค่าคุณสมบัตินี้จากองค์ประกอบหลัก |
| หมายเลข | แสดงหมายเลขที่ระบุลำดับของรายการที่ยืดหยุ่นได้ |
ให้เรามาดูตัวอย่าง HTML DOM Style order Property -
ตัวอย่าง
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.container {
border: 3px solid #fff;
margin: 1rem auto;
display: flex;
padding: 2rem;
}
.box {
width: 100px;
height: 100px;
}
</style>
<body>
<h1 style="text-align:center">DOM Style order Property Demo</h1>
<div class="container">
<div class="box" id="b1" style="background-color:#7F055F;"></div>
<div class="box" id="b2" style="background-color:#3A015C;"></div>
<div class="box" id="b3" style="background-color:#177E89;"></div>
</div>
<button onclick="set()" class="btn">Change order</button>
<script>
function set() {
document.querySelector('#b1').style.order = "3";
document.querySelector('#b2').style.order = "2";
document.querySelector('#b3').style.order = "1";
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “เปลี่ยนคำสั่งซื้อ ” เพื่อเปลี่ยนลำดับของรายการที่ยืดหยุ่นภายใน สีขาว คอนเทนเนอร์ชายแดน
