Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าว่าองค์ประกอบสามารถปรับขนาดได้โดยผู้ใช้หรือไม่ด้วย JavaScript


ใช้คุณสมบัติ resize เพื่อตั้งค่าว่าองค์ประกอบสามารถปรับขนาดได้โดยผู้ใช้หรือไม่

ตัวอย่าง

คุณสามารถลองรันโค้ดต่อไปนี้เพื่อตั้งค่าว่าองค์ประกอบสามารถปรับขนาดได้โดยผู้ใช้ด้วย JavaScript −

<!DOCTYPE html> <html>    <head>       <style>          #box {             width: 350px;             overflow: auto;             background-color: orange;             border: 3px solid red;          }       </style>    </head>    <body>       <p>Click to set the right position.</p>       <button type = "button" onclick = "display()"> Set Right Position </button>      <div id = "box">         <p>This is a div. This is a div. This is a div. This is a div.<p>         <p>This is a div. This is a div. This is a div. This is a div.<p>         <p>This is a div. This is a div. This is a div. This is a div.<p>      </div>             <br>       <br>       <script>       function display() {          document.getElementById("box").style.resize = "both";       }       </script>    </body> </html>