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

วิธีตั้งค่าพื้นที่การระบายสีพื้นหลังด้วย JavaScript


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

ตัวอย่าง

<!DOCTYPE html> <html>    <head>       <style>          #box {             border: 2px dashed green;             padding: 35px;             width: 600px;             height: 400px;             background-color: blue;             background-clip: border-box;          }       </style>    </head>    <body>       <button onclick="display()">Set painting area</button>       <div id="box">          This is Demo Text! This is Demo Text! This is Demo Text!          This is Demo Text! This is Demo Text!       </div>       <script>          function display() {             document.getElementById("box").style.backgroundClip = "content-box";          }       </script>    </body> </html>