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

เมธอด HTML DOM console.groupEnd()

เมธอด HTML DOM console.groupEnd() ใช้สำหรับระบุจุดสิ้นสุดของกลุ่มข้อความ มันออกจากกลุ่มข้อความปัจจุบันในคอนโซล

ไวยากรณ์

ไวยากรณ์สำหรับเมธอด console.groupEnd() ดังนี้ -

console.groupEnd()

ตัวอย่าง

ลองดูตัวอย่างสำหรับเมธอด HTML DOM console.groupEnd() -

<!DOCTYPE html> <html> <body> <h1>console.groupEnd() Method</h1> <p>กด F12 เพื่อดูข้อความในมุมมองคอนโซล</p> <button type="button" onclick="groupMessage()">GROUP</button> <button type="button" onclick="EndGroup()">END GROUP</button> <script> function groupMessage(){ console.group(); console.log("This message will be inside a group!"); console.log("This message will also be inside a group!"); } function EndGroup(){ console.groupEnd(); console.log("We are now outside the group"); console.log("This message will be outside the group!"); } </script> </body> </html>

ผลลัพธ์

จะได้ผลลัพธ์ดังนี้ -

เมธอด HTML DOM console.groupEnd()

เมื่อคลิกปุ่ม GROUP และดูมุมมองคอนโซลในตัวเลือกพัฒนา -

เมธอด HTML DOM console.groupEnd()

เมื่อคลิกปุ่ม END GROUP และดูมุมมองคอนโซลในตัวเลือกพัฒนา -

เมธอด HTML DOM console.groupEnd()

ในตัวอย่างข้างต้น -

เราสร้างปุ่มสองปุ่ม GROUP และ END GROUP ที่จะเรียกใช้ groupMessage() และ EndGroup() เมื่อถูกคลิกโดยผู้ใช้ -

<button type="button" onclick="groupMessage()">GROUP</button> <button type="button" onclick="EndGroup()">END GROUP</button>

เมธอด groupMessage() มีเมธอด console.group() ภายในระบุว่าข้อความทั้งหมดที่เขียนหลังจุดนี้จะแสดงภายในกลุ่มข้อความ -

function groupMessage(){ console.group(); console.log("This message will be inside a group!"); console.log("This message will also be inside a group!"); }

เมธอด EndGroup() มีเมธอด console.groupEnd() ภายในระบุว่าข้อความทั้งหมดที่เขียนหลังจุดนี้จะแสดงนอกกลุ่มข้อความ มันจะไม่โยนข้อผิดพลาดหากไม่มีกลุ่มข้อความก่อนหน้า -

function EndGroup(){ console.groupEnd(); console.log("We are now outside the group"); console.log("This message will be outside the group!"); }