[研究]ASP.NET + JavaScript Alert 彈出對話盒視窗換行測試 vs 彈出對話盒視窗沒出現研究
2022-03-18
2022-03-19更新
嚴格來說,
\r (CR, Carriage Return)是回車,游標回到開頭,ASCII 碼 13 = \x0d,UniCode 碼 U+000D
\n (LF, Line Feed)是換行,游標到下一行,沒有回到開頭,ASCII 碼 10 = \x0a,UniCode 碼 U+000A
但在不同的場合,可能只使用其中一種就兼具回到開頭和換行。https://zh.wikipedia.org/wiki/%E6%8F%9B%E8%A1%8C
- LF:在Unix或Unix相容系統(GNU/Linux,AIX,Xenix,Mac OS X,...)、BeOS、Amiga、RISC OS
- CR+LF:DOS(MS-DOS、PC-DOS等)、微軟視窗作業系統(Microsoft Windows)、大部分非Unix的系統
- CR:Apple II家族,Mac OS至版本9
Test.htm
<html> <head> <script language='javascript' defer>alert('換行測試1\n換行測試');</script> <script language='javascript' defer>alert('換行測試2\r換行測試');</script> <script language='javascript' defer>alert('換行測試3\\n換行測試');</script> <script language='javascript' defer>alert('換行測試4\\r換行測試');</script> <script language='javascript' defer>alert('換行測試5\n\r換行測試');</script> <script language='javascript' defer>alert('換行測試6\r\n換行測試');</script> </head> </html> |
單獨的 \r 和 \n 意義相同,但 \n\r 和 \r\n 意義不同。
兩個 \\ 會當成真正要顯示 \ 使用,而非有特殊用途。
********************************************************************************
Visual Studio 2022 + ASP.NET + WebForm + Web Application
WebForm1.aspx
using System; using System.Web.UI; namespace WebApplication16 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試1<br />換行測試');</script>"); } protected void Button2_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試2\\n換行測試');</script>"); } protected void Button3_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試3\\r換行測試');</script>"); } protected void Button4_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試4\n換行測試');</script>"); } protected void Button5_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試5\r換行測試');</script>"); } protected void Button6_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試6\u000d換行測試');</script>"); } protected void Button7_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試7\u000a換行測試');</script>"); } protected void Button8_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試8\\u000d換行測試');</script>"); } protected void Button9_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('換行測試9\\u000a換行測試');</script>"); } } } |
可以發現 ASP.NET 用 Page.ClientScript.RegisterStartupScript 來使用 JavaScript Alert 視窗時,必須使用兩個倒斜線才可以讓對話盒視窗顯示和換行,否則連彈出視窗都沒了。
********************************************************************************
2022-03-19
Test2.htm
<html> <head> <script language='javascript' defer>alert('換行測試11 換行測試');</script> </head> </html> |
(完)
相關
[研究][ASP.NET]JavaScript alert對話盒視窗彈出位置測試
https://shaurong.blogspot.com/2022/04/aspnetjavascript-alert.html
[研究]ASP.NET + JavaScript Alert 彈出視窗換行測試 vs 彈出視窗沒出現研究
https://shaurong.blogspot.com/2022/03/javascript-alert.html
[研究]HTML, CSS, JavaScript, jQuery, jQuery UI, Bootstrap 彈出對話盒視窗
https://shaurong.blogspot.com/2020/11/html-css-javascript-jquery-jquery-ui.html
[研究]]JavaScript] 用 orangehill / bootstrap-session-timeout 做 Session Time Out 前 N 秒自動彈出對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-orangehill-bootstrap-session.html
[研究][JavaScript] 用 session-timeout.js 做 Session Time Out 前 N 秒自動彈出對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-session-timeoutjs-session.html
[研究][JavaScript]Master Page 用 idle-timer.js 做 Session Time Out 前 N 秒自動彈出倒數計時對話盒視窗
https://shaurong.blogspot.com/2020/11/javascriptcaspnetwebform-master-page.html
[研究][JavaScript] 用 idle-timer.js 做 Session Time Out 前 N 秒自動彈出倒數計時對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-idle-timerjs-session-time.html
[研究][JavaScript] 用 timeout-dialog.js 做 Session Time Out 前 60 秒自動彈出倒數計時對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-timeout-dialogjs-session.html
[研究][C#] [ASP.NET] [JavaScript] 彈出視窗 (對話盒)
https://shaurong.blogspot.com/2020/04/c-aspnet-javascript.html
[研究][C#] [ASP.NET] [JavaScript] 彈出視窗
https://shaurong.blogspot.com/2017/06/c-aspnet-javascript.html
沒有留言:
張貼留言