หากต้องการเพิ่มบรรทัดใหม่ในกล่องแจ้งเตือน JavaScript ให้ใช้ “\n”:
alert("Line One\n Line Two"); ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้ เพิ่มบรรทัดใหม่ในกล่องแจ้งเตือนใน JavaScript:
การสาธิตสด
<html>
<head>
<script>
<!--
function Warn() {
alert ("This is a warning message!\nThis is a new line.");
document.write ("This is a warning message!");
}
//-->
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="Warn();" />
</form>
</body>
</html>