หากต้องการจัดรูปแบบภาพพื้นหลังให้ไม่ซ้ำด้วย JavaScript ให้ใช้คุณสมบัติ backgroundRepeat คุณสมบัตินี้ช่วยให้คุณตั้งค่าได้ว่าภาพพื้นหลังจะซ้ำหรือไม่บนหน้าเว็บ
ตัวอย่าง
คุณสามารถลองรันโค้ดต่อไปนี้เพื่อเรียนรู้วิธีจัดรูปแบบภาพพื้นหลังให้ไม่ซ้ำด้วย JavaScript −
<!DOCTYPE html> <html> <body> <button onclick="display()">Click to Set background image</button> <script> function display() { document.body.style.backgroundImage = "url('https://www.tutorialspoint.com/html5/images/html5-mini-logo.jpg')"; document.body.style.backgroundRepeat = "no-repeat"; } </script> </body> </html>