Để thêm một dòng mới trong hộp cảnh báo JavaScript, hãy sử dụng “\ n”:
alert("Line One\n Line Two"); Ví dụ
Bạn có thể thử chạy đoạn mã sau, thêm dòng mới vào hộp cảnh báo bằng JavaScript:
Bản trình diễn trực tiếp
<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>