顯示具有 HTML 標籤的文章。 顯示所有文章
顯示具有 HTML 標籤的文章。 顯示所有文章

2025年12月3日 星期三

[研究]HTML、CSC表格內外框線

[研究]HTML、CSC表格內外框線

2025-12-03

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2

********************************************************************************

某 <table border="1"> 只會產生 表格外框 的線,但內部 不會有格線,解決方法。

方式 1:使用 border-collapse: collapse 搭配 CSS 邊框

<table style="border-collapse: collapse; border: 1px solid black;">
  <tr>
    <th style="border: 1px solid black;">欄位1</th>
    <th style="border: 1px solid black;">欄位2</th>
  </tr>
  <tr>
    <td style="border: 1px solid black;">資料1</td>
    <td style="border: 1px solid black;">資料2</td>
  </tr>
</table>

方式 2:用全局 CSS 樣式(建議)

<style>
  table {
    border-collapse: collapse; /* 合併邊框 */
    border: 1px solid black;   /* 表格外框 */
  }
  th, td {
    border: 1px solid black;   /* 每個儲存格邊框 */
    padding: 5px;              /* 內距,看起來不擠 */
  }
</style>

<table>
  <tr>
    <th>欄位1</th>
    <th>欄位2</th>
  </tr>
  <tr>
    <td>資料1</td>
    <td>資料2</td>
  </tr>
</table>

方式 3:用 id(只影響那一個 table)

HTML

<style>
  #MyTable {
    border-collapse: collapse;   
    border: 1px solid black;
  }
  #MyTable th,
  #MyTable td {
    border: 1px solid black;
    padding: 5px;
  }
</style> <table id="MyTable"> <tr> <th>欄位1</th> <th>欄位2</th> </tr> <tr> <td>資料1</td> <td>資料2</td> </tr> </table>

方式 4:用 class(可套用到多個表格)

<style>
  .bordered-table {
    border-collapse: collapse;
    border: 1px solid black;
  }
  .bordered-table th,
  .bordered-table td {
    border: 1px solid black;
    padding: 5px;
  }
</style>

<table class="bordered-table">   
  <tr>
    <th>欄位1</th>
    <th>欄位2</th>
  </tr>
  <tr>
    <td>資料1</td>
    <td>資料2</td>
  </tr>
</table>

(完)

相關

2023年4月25日 星期二

[研究]HTML Tag 標籤對稱檢查 (Unclosed Tag Checker)

[研究]HTML Tag 標籤對稱檢查

2023-04-24

Find Unclosed Tags - Unclosed Tag Checker - HTML5 - by Alicia Ramirez
https://www.aliciaramirez.com/closing-tags-checker/



**********

Jon Aquino's Mental Garden: Unclosed Tag Finder
http://jonaquino.blogspot.com/2013/05/unclosed-tag-finder.html

**********

免費的在線 HTML 驗證器 - FreeFormatter.com
https://www.freeformatter.com/html-validator.html



(待續)

2023年3月20日 星期一

[研究][ASP.NET]CSS Grid Item 的 Bug 迴避

[研究][ASP.NET]CSS Grid Item 的 Bug 迴避

2023-03-20

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

********************************************************************************

發現網站導覽一些區塊排列順序不如預期 ( Code 類似下面),經檢查,假設9個,一橫列顯示3個區塊,第4塊出現於第1,2,3區塊橫列數最少的下方,而不一定是第二橫列最左方。避開Bug方法,讓每個區塊的<li>數量一致,不足的補上 <li>&nbsp;</li>。

調整後發現仍有問題,因為有的<li>項目,顯示文字太長,自動換行,占用了2橫列,重新統計9個區塊每個區塊的顯示列數,而非 <li> 數量,以最大值為主,其他都補放  <li>&nbsp;</li>,這次正常了。

Default.html

<div class="grid">
	<div class="grid-item ml-sitemap-box">
         <div class="title"><a href="#" title="AAAAA">AAAAA</a></div>
         <ul>
             <li><a href="bb.aspx?lang=zh" title="BBBBB">BBBBB</a></li>
             <li><a href="cc.aspx?lang=zh" title="CCCCC">CCCCC</a></li>
             <li><a href="dd.aspx?lang=zh" title="DDDDD">CCCCC</a></li>
         </ul>
     </div>
     <div class="grid-item ml-sitemap-box">
         <div class="title"><a href="#" title="XXXXX">XXXXX</a></div>
         <ul>
             <li><a href="yy.aspx?lang=zh" title="YYYYY">YYYYY</a></li>
             <li><a href="zz.aspx?lang=zh" title="ZZZZZ">ZZZZZ</a></li>
	     <li>&nbsp;</li>
         </ul>
     </div>
 </div>
ㄗ

此作法並沒有修正 Gird 本身問題,只是用某些做法避開 Bug 。

(完)

相關

CSS Grid Item
https://www.w3schools.com/css/css_grid_item.asp


2022年6月10日 星期五

[研究]單一或多個 Email 格式驗證 (使用 HTML5)

[研究]單一或多個 Email 格式驗證 (使用 HTML5)

2022-06-10

在HTML5問世前,輸入資料是否符合 Email 格式,要自己想辦法處理。

HTML 5 提供 inpuit 標籤 type屬性值為 email 時,可以驗證輸入內容是否符合單一 Email 格式;若再多加一個 multiple 屬性,則驗證是否符合多個 Email。

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

Default2.aspx

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Default2.aspx.cs" Inherits="WebApplication1.Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        Single Email 1:<asp:TextBox ID="TextBox1" Type="email" runat="server"></asp:TextBox><br />
        Single Email 2:<input id="Text1" type="email" /><br />

        Multiple Email 1:<asp:TextBox ID="TextBox2" Type="email" multiple runat="server"></asp:TextBox><br />
        Multiple Email 2:<asp:TextBox ID="TextBox3" Type="email" multiple="multiple" runat="server"></asp:TextBox><br />
        Multiple Email 3:<input id="Text2" type="email" multiple /><br />
        Multiple Email 4:<input id="Text3" type="email" multiple="multiple" /><br />
        <asp:Button ID="Button1" runat="server" Text="Send" />
    </form>
</body>
</html>


部分程式碼底下被標記成綠色波浪線



所以另外測試把 multiple 寫成 multiple="multiple",其實 HTML5 直接使用 multiple 即可。只是 ASP.NET 和 XHTML5 任為不該這樣寫,但編譯或執行都是正常的。

********************************************************************************

實際測試一下

(下圖) type="email" 是允許不填內容,只是若填寫,一定要符合 Email 格式。

如果強迫要填寫,加個  required 或 required="required" 屬性吧。

















********************************************************************************

六種寫法的測試結果圖不全部呈現,僅呈現單一和多個 Email 的狀況,另外發現半形空白會自動被移除,不管半形空白出現在開頭、中間、結尾 (有實測,沒特別抓圖),不管是單一或多個Email輸入。

多個Email分隔必須使用半形逗號,半形分號不行。( Microsoft Outlook 2019 的收件者若有多個 Email 是半形分號來分隔,半形分號不行,習慣不同 )

前端的檢查,對於駭客是可以用Burp Suite或其他工具或手法繞過,所以不管前端是否檢查,若要檢查,伺服器端的檢查是必須的。

[研究][ASP.NET]單一或多個 Email 格式驗證 (使用C#)
https://shaurong.blogspot.com/2022/06/aspnet-email-c.html

(完)


2022年4月12日 星期二

[研究][ASP.NET]HTML5 的 input 標籤的 type 屬性的 日期、月曆測試

[研究][ASP.NET]HTML5 的 input 標籤的 type 屬性的 日期、月曆測試

2022-04-12

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

HTML Standard
https://html.spec.whatwg.org/multipage/input.html#the-input-element

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" 
    Inherits="WebApplication1.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            datetime-local:
            <asp:TextBox ID="TextBox1" Type="datetime-local" runat="server"></asp:TextBox><br />
            datetime:
            <asp:TextBox ID="TextBox2" Type="datetime" runat="server"></asp:TextBox><br />
            date:
            <asp:TextBox ID="TextBox3" Type="date" runat="server"></asp:TextBox><br />
            time:
            <asp:TextBox ID="TextBox4" Type="time" runat="server"></asp:TextBox><br />
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
            <asp:Label ID="Label1" runat="server"></asp:Label><br />
            <asp:Label ID="Label2" runat="server"></asp:Label><br />
            <asp:Label ID="Label3" runat="server"></asp:Label><br />
            <asp:Label ID="Label4" runat="server"></asp:Label><br />
        </div>
    </form>
</body>
</html>
 

Default.aspx.cs

using System;

namespace WebApplication1
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = TextBox1.Text;
            Label2.Text = TextBox2.Text;
            Label3.Text = TextBox3.Text;
            Label4.Text = TextBox4.Text;
        }
    }
}

(下圖)執行結果(Chrome 100)

(下圖) Type="datetime-local"

(下圖) Type="datetime"


其中 datetime-local 輸入的結果 2202-04-12T07:45有個英文字母 T,和一般習慣不同,待會測試看看寫入資料庫會變成甚麼。

如果選擇 22022/4/12 下午 02:48,會顯示 2022-04-12T14:48,仍使用英文字母 T。

********************************************************************************

寫入資料庫測試

Default2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="WebApplication1.Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:TestDB5ConnectionString %>" 
                DeleteCommand="DELETE FROM [Table1] WHERE [SN] = @SN" 
                InsertCommand="INSERT INTO [Table1] ([date1], [date2], [date3], [date4]) VALUES (@date1, @date2, @date3, @date4)" 
                SelectCommand="SELECT * FROM [Table1]" 
                UpdateCommand="UPDATE [Table1] SET [date1] = @date1, [date2] = @date2, [date3] = @date3, [date4] = @date4 WHERE [SN] = @SN">
                <DeleteParameters>
                    <asp:Parameter Name="SN" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="date1" Type="DateTime" />
                    <asp:Parameter Name="date2" Type="DateTime" />
                    <asp:Parameter Name="date3" Type="DateTime" />
                    <asp:Parameter Name="date4" Type="DateTime" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="date1" Type="DateTime" />
                    <asp:Parameter Name="date2" Type="DateTime" />
                    <asp:Parameter Name="date3" Type="DateTime" />
                    <asp:Parameter Name="date4" Type="DateTime" />
                    <asp:Parameter Name="SN" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <asp:ListView ID="ListView1" runat="server" DataKeyNames="SN" 
                DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
                <AlternatingItemTemplate>
                    <tr style="">
                        <td>
                            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="刪除" />
                            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="編輯" />
                        </td>
                        <td>
                            <asp:Label ID="SNLabel" runat="server" Text='<%# Eval("SN") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date1Label" runat="server" Text='<%# Eval("date1") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date2Label" runat="server" Text='<%# Eval("date2") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date3Label" runat="server" Text='<%# Eval("date3") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date4Label" runat="server" Text='<%# Eval("date4") %>' />
                        </td>
                    </tr>
                </AlternatingItemTemplate>
                <EditItemTemplate>
                    <tr style="">
                        <td>
                            <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
                            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />
                        </td>
                        <td>
                            <asp:Label ID="SNLabel1" runat="server" Text='<%# Eval("SN") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date1TextBox" runat="server" Text='<%# Bind("date1") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date2TextBox" runat="server" Text='<%# Bind("date2") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date3TextBox" runat="server" Text='<%# Bind("date3") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date4TextBox" runat="server" Text='<%# Bind("date4") %>' />
                        </td>
                    </tr>
                </EditItemTemplate>
                <EmptyDataTemplate>
                    <table runat="server" style="">
                        <tr>
                            <td>未傳回資料。</td>
                        </tr>
                    </table>
                </EmptyDataTemplate>
                <InsertItemTemplate>
                    <tr style="">
                        <td>
                            <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
                            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            <asp:TextBox ID="date1TextBox" Type="datetime-local" runat="server" Text='<%# Bind("date1") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date2TextBox" Type="datetime" runat="server" Text='<%# Bind("date2") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date3TextBox" Type="date" runat="server" Text='<%# Bind("date3") %>' />
                        </td>
                        <td>
                            <asp:TextBox ID="date4TextBox" Type="time" runat="server" Text='<%# Bind("date4") %>' />
                        </td>
                    </tr>
                </InsertItemTemplate>
                <ItemTemplate>
                    <tr style="">
                        <td>
                            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="刪除" />
                            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="編輯" />
                        </td>
                        <td>
                            <asp:Label ID="SNLabel" runat="server" Text='<%# Eval("SN") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date1Label" runat="server" Text='<%# Eval("date1") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date2Label" runat="server" Text='<%# Eval("date2") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date3Label" runat="server" Text='<%# Eval("date3") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date4Label" runat="server" Text='<%# Eval("date4") %>' />
                        </td>
                    </tr>
                </ItemTemplate>
                <LayoutTemplate>
                    <table runat="server">
                        <tr runat="server">
                            <td runat="server">
                                <table id="itemPlaceholderContainer" runat="server" border="0" style="">
                                    <tr runat="server" style="">
                                        <th runat="server"></th>
                                        <th runat="server">SN</th>
                                        <th runat="server">date1</th>
                                        <th runat="server">date2</th>
                                        <th runat="server">date3</th>
                                        <th runat="server">date4</th>
                                    </tr>
                                    <tr id="itemPlaceholder" runat="server">
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr runat="server">
                            <td runat="server" style="">
                                <asp:DataPager ID="DataPager1" runat="server">
                                    <Fields>
                                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
                                    </Fields>
                                </asp:DataPager>
                            </td>
                        </tr>
                    </table>
                </LayoutTemplate>
                <SelectedItemTemplate>
                    <tr style="">
                        <td>
                            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="刪除" />
                            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="編輯" />
                        </td>
                        <td>
                            <asp:Label ID="SNLabel" runat="server" Text='<%# Eval("SN") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date1Label" runat="server" Text='<%# Eval("date1") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date2Label" runat="server" Text='<%# Eval("date2") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date3Label" runat="server" Text='<%# Eval("date3") %>' />
                        </td>
                        <td>
                            <asp:Label ID="date4Label" runat="server" Text='<%# Eval("date4") %>' />
                        </td>
                    </tr>
                </SelectedItemTemplate>
            </asp:ListView>
        </div>
    </form>
</body>
</html>


Default2.aspx.cs 沒有進行編寫。

(下圖)執行結果(Chrome 100)





其中 datetime-local 選擇 2202-04-12 上午 07:57 寫入資料庫變成 2202-04-12 07:57:00.000。

其中 datetime 手動輸入(沒月曆可選) 2202-04-12 07:57 寫入資料庫變成 2202-04-12 07:57:00.000。

其中 date  2202-04-12 寫入資料庫變成 2202-04-12 07:57:00.000。(自動加上時間了)

其中 time  07:57 寫入資料庫變成 2202-04-12 07:57:00.000。(自動加上日期了)

********************************************************************************

ASP.NET + SQL  Server + 防 SQL Injection 的參數化查詢

因為字母T關係,字串要做一下取代動作 換成一個半型空白字元,否則會出錯。

TextBox1.Text.Replace("T", " ")

********************************************************************************

2022-06-20 補,「新增」模式OK,但不太合適用於「編輯」模式,值無法顯示



********************************************************************************

(完)

相關

[研究]HTML5 的 input 標籤的 type 屬性的 日期、月曆測試
https://shaurong.blogspot.com/2022/04/html5-input-type_12.html

[研究]HTML5 的 input 標籤的 type 屬性的各種值
https://shaurong.blogspot.com/2022/04/html5-input-type.html

[研究][ASP.NET]jQuery 3.6.0 物件沒有支援這個屬性或方法 'datepicker'
https://shaurong.blogspot.com/2022/03/aspnetjquery-360-datepicker.html

[研究][ASP.NET][JavaScript]jQuery.UI.Combined.1.13.1 的 datepicker 與 jQuery 3.6.0 相容測試https://shaurong.blogspot.com/2022/03/aspnetjqueryuicombined1131-datepicker.html

[研究][JavaScript] jQuery Date and Time picker 2.4.5 (jquery-datetimepicker)(NuGet 安裝)
https://shaurong.blogspot.com/2018/03/javascript-jquery-date-and-time-picker.html

[研究][ASP.NET][JavaScript] Bootstrap V3 Datetimepicker 4.17.45 月曆 套件 安裝與試用https://shaurong.blogspot.com/2018/03/bootstrap-v3-datepicker-41745.html

[研究][ASP.NET][JavaScript] Bootstrap Datepicker 1.7.1 月曆 套件 安裝與試用https://shaurong.blogspot.com/2018/03/bootstrap-datepicker-171.html

[研究][ASP.NET][JavaScript] jQuery UI v1.12.1 的 Datepicker 月曆 套件 安裝與試用https://shaurong.blogspot.com/2017/07/jquery-ui-datepicker.html



2020年11月23日 星期一

[研究] HTML, CSS, JavaScript, jQuery, jQuery UI, Bootstrap 彈出對話盒視窗

[研究] HTML, CSS, JavaScript,  jQuery, jQuery UI, Bootstrap 警告(Alert)、對話盒 (Dialog)、彈出視窗(Popup Window)、彈出對話盒(Popup Dialog)、彈出對話盒視窗(Popup Dialog Window)

2020-11-23

HTML 對話盒視窗因為是平面式而非彈出式,少人用。

CSS 對話盒視窗感覺是平面式的,只是Modal會以區塊覆蓋顯示於其他內容上。

JavaScript 彈出對話盒視窗是比較多人用的。但以 alert()、confirm()、prompt()、windows.open() 較常用,其他較少用,且非每種瀏覽器或版本都支援,有些雖支援,但預設沒有啟用。

jQuery 是用 JavaScript 開發的,沒有特別提供的對話盒。

jQuery UI 需要 jQuery,主要強化 UI ( User Interface,使用者介面) 部分。

BootStrap 3.x 和 4.x 需要 jQuery,但未來推出的 5.x 不需要 jQeury。BootStrapAlert對話盒是平面式而非彈出式,少人用。Bootstrap Modal Plugin 是彈出式的。

比較進階強化的對話盒,混用的 HTML, CSS, JavaScript,  jQuery, jQuery UI, Bootstrap 等標準和技術。網路上某些程式範例,可能已經淘汰,或不支援新版的套件,無法正常運作。

********************************************************************************

HTML

HTML <dialog> Tag

https://www.w3schools.com/tags/tag_dialog.asp

HTML 範例:<dialog open>This is an open dialog window</dialog>

(下圖) 直接顯示在網頁上的對話盒視窗,而非彈出式的。

可用下面 JavaScript 操作 (但也可操作非 HTML <dialog> Tag )

HTML DOM Dialog Object,包含 document.getElementById(), document.createElement(), open, close(), show(), showModal() 等。 

https://www.w3schools.com/jsref/dom_obj_dialog.asp

********************************************************************************

CSS

W3.CSS Alerts,平面式警告對話盒,其實是使用 w3-panel

https://www.w3schools.com/w3css/w3css_alerts.asp

W3.CSS Modal

https://www.w3schools.com/w3css/w3css_modal.asp



<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>

<div class="w3-container">
  <h2>W3.CSS Modal</h2>
  <button onclick="document.getElementById('id01').style.display='block'" class="w3-button w3-black">Open Modal</button>
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test 
  <div id="id01" class="w3-modal">
    <div class="w3-modal-content">
      <div class="w3-container">
        <span onclick="document.getElementById('id01').style.display='none'" class="w3-button w3-display-topright">&times;</span>
        <p>Some text. Some text. Some text.</p>
        <p>Some text. Some text. Some text.</p>
      </div>
    </div>
  </div>
</div>
            
</body>
</html>

(下圖)看起來像是平面式的對話盒,只是會覆蓋顯示於其他網頁內容上。

********************************************************************************

JavaScript

alert()、confirm()、prompt()

https://www.w3schools.com/js/js_popup.asp

alert()

https://www.w3schools.com/jsref/met_win_alert.asp

****************************************

confirm()

https://www.w3schools.com/jsref/met_win_confirm.asp

****************************************

prompt()

https://www.w3schools.com/jsref/met_win_prompt.asp


****************************************

windows.open() 

https://www.w3schools.com/jsref/met_win_open.asp

另外開啟新瀏覽器視窗,載入某址的網頁

****************************************

HTML DOM Dialog Object,包含 document.getElementById(), document.createElement(), open, close(), show(), showModal() 等。 

https://www.w3schools.com/jsref/dom_obj_dialog.asp

JavaScript 建立:var x = document.createElement("DIALOG");

JavaScript 存取:var x = document.getElementById("myDialog");

JavaScript,判斷是否開啟(不會實際去開啟):var x = document.getElementById("myDialog").open;

https://www.w3schools.com/jsref/prop_dialog_open.asp

Dialog close() Method

https://www.w3schools.com/jsref/met_dialog_close.asp

showModal()

https://www.w3schools.com/jsref/met_dialog_showmodal.asp



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <p>Click the button to show the dialog.</p>
    <button onclick="myFunction()">Show dialog</button>
    <p><b>Note:</b> Use the "Esc" button to close the modal.</p>
    <p><b>Note:</b> The dialog element is only supported in Chrome 37+, Safari 6+ and Opera 24+.</p>
    <dialog id="myDialog">This is a dialog window</dialog>
    <script>
        function myFunction() {
            document.getElementById("myDialog").showModal();
        }
    </script>
</body>
</html>

(下圖)Google Chrome 版本 87.0.4280.66 (正式版本) (64 位元)、Miccrosoft Edge 86



(下圖) IE11


FireFox 83 按下「Show Dialog」按鈕沒有反應。

****************************************

showModalDialog() 和 showModalessDialog() 不是標準,僅某些瀏覽器和版本支援。

********************************************************************************

jQuery UI

jQuery UI 需要 jQuery,主要強化 UI ( User Interface,使用者介面) 部分。

Dialog

https://jqueryui.com/dialog/

官方範例使用的路徑稍作修正如下

Test.htm


<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog" ).dialog();
  } );
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the &apos;x&apos; icon.</p>
</div>
 
 
</body>
</html>

(下圖) 執行結果

********************************************************************************

Bootstrap

Bootstrap Alert ( Bootstrap 3 和 4 需要 jQuery, 未來Bootstrap 5 不需要 jQuery)

https://www.w3schools.com/bootstrap/bootstrap_alerts.asp


<div class="alert alert-success">
  <strong>Success!</strong> Indicates a successful or positive action.
</div>

<div class="alert alert-info">
  <strong>Info!</strong> Indicates a neutral informative change or action.
</div>

<div class="alert alert-warning">
  <strong>Warning!</strong> Indicates a warning that might need attention.
</div>

<div class="alert alert-danger">
  <strong>Danger!</strong> Indicates a dangerous or potentially negative action.
</div>

Bootstrap Alert 比較不像 JavaScript 傳統 alert(),它不會彈出對話盒或彈出視窗,而是平面文字框,比較像是用 CSS 去達成的。

****************************************

Bootstrap Modal Plugin

https://www.w3schools.com/bootstrap/bootstrap_modal.asp

only supported in Chrome 37+, Safari 6+ and Opera 24+.


<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>
  
</div>

</body>
</html>

(下圖) 對話盒是彈出式的

********************************************************************************


(完)

相關

谷歌,火狐瀏覽器不支援showModalDialog的解決方法

其他 · 發表 2019-02-13

https://www.itread01.com/content/1549994237.html