Does anyone know how to make an alert box in HTML that has multiple lines? I looking for the output to be something like this:
Rules:
1. Blah Blah Blah
2. Blah Blah Blah
3. Blah Blah Blah
[Cancel] [Ok]
Here is the code so far in javascript:
function rules() { agree = confirm("RULES: 1. Blah Blah Blah<br> 2. Blah Blah Blah<br> 3. Blah Blah Blah<br> Press OK to agree and Cancel to Dissagree") if (agree == true) { alert("Thank you for agreeing to the rules!") } else { alert("You can not move on unless you agree to the rules.") } }
<button onclick="rules()">Agree to the Rules</button>
I tried using <br>
, but those don't seem to format in alert boxes. The output I get is this:
Does anyone know how I can add another line into an alert box?
alert("这是第一行\\n这是第二行\\n这是第三行");
inserting \\n creates a new Line
function rules() { agree = confirm("RULES: 1. Bl\\nah Blah Blah 2. Bla\\nh Blah Blah 3. Bla\\nh Blah Blah Press OK to agree and Cancel to Dissagree") if (agree == true) { alert("Thank you for agreeing to the rules!") } else { alert("You can not move on unless you agree to the rules.") } }
<button onclick="rules()">Agree to the Rules</button>
After doing some research, I found an answer to my question.
To easily create an alert box with multiple lines, use \\n
.
function rules() { agree = confirm("RULES: \\n1. Blah Blah Blah \\n2. Blah Blah Blah \\n3. Blah Blah Blah \\nPress OK to agree and Cancel to Dissagree") if (agree == true) { alert("Thank you for agreeing to the rules!") } else { alert("You can not move on unless you agree to the rules.") } }
<button onclick="rules()">Agree to the Rules</button>
I hope this helps anyone who was wondering this!
You would use '\\n'
for creating lines.
For example, your rules string would be:
'Rules:\n1. Blah Blah Blah\n2. Blah Blah Blah\n3. Blah Blah Blah'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.