顯示具有 jQuery UI 標籤的文章。 顯示所有文章
顯示具有 jQuery UI 標籤的文章。 顯示所有文章

2023年3月7日 星期二

[研究]jQuery 和 jQuery UI的 CDN 網址

[研究]jQuery 和 jQuery UI的 CDN 網址

2023-03-07

jQuery CDN:

https://releases.jquery.com/jquery/

<script src="https://code.jquery.com/jquery-3.6.3.js" integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM=" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>

可以簡寫為

<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>

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

jQuery UI CDN:

https://releases.jquery.com/ui/

<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js" integrity="sha256-eTyxS0rkjpLEo16uXTS0uVCS4815lc40K2iVpWDvdSY=" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css" />

https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css

https://code.jquery.com/ui/1.13.1/jquery-ui.min.js

https://code.jquery.com/ui/1.13.1/themes/smoothness/jquery-ui.css

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

非官方CDN

Google CDN:

jQuery.min.js:https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js

jQuery.min.css:https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/themes/smoothness/jquery-ui.css

Microsoft CDN:

jQuery.min.js:https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.3.min.js

jQuery.min.css:https://ajax.aspnetcdn.com/ajax/jquery.ui/1.13.2/themes/smoothness/jquery-ui.css

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

(完)

相關

[研究]jQuery 和 jQuery UI的 CDN 網址
https://shaurong.blogspot.com/2023/03/jquery-jquery-ui-cdn.html

[研究]Bootstrap 3.x, 4.x, 5.x的官方 CDN 網址
https://shaurong.blogspot.com/2023/03/bootstrap-3x-4x-5x-cdn.html

[研究]CKEditor 4.x、5.x的官方 CDN 網址
https://shaurong.blogspot.com/2023/03/ckeditor-4x5x-cdn.html


2022年3月21日 星期一

[研究][ASP.NET]錯誤: 無法取得未定義或 Null 參考的屬性 'setDefaults'

[研究][ASP.NET]錯誤: 無法取得未定義或 Null 參考的屬性 'setDefaults'

2022-03-20

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



行: 18

錯誤: 無法取得未定義或 Null 參考的屬性 'setDefaults'

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

解決:搜尋整個方案,把 jQuery UI 的 1.12.1 改成 1.13.1。詳情請看

[研究][ASP.NET]jQuery 3.6.0 物件沒有支援這個屬性或方法 'datepicker'

(完)


2022年3月19日 星期六

[研究][ASP.NET]jQuery.UI.Combined.1.13.1 的 datepicker 與 jQuery 3.6.0 相容測試

[研究][ASP.NET][JavaScript]jQuery.UI.Combined.1.13.1 的 datepicker 與 jQuery 3.6.0 相容測試

2022-3-19

因為這篇,敝人想測試一下目前最新 jQuery UI 的 datepicker 和 jQuery 3.6.0 相容性

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

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

NuGet 安裝 jQuery.UI.Combined.1.13.1時,實際上會安裝 jQuery.2.0.0 和 jQuery.UI.Combined.1.13.1,然後再把 jQuery 2.0.0 升級到 jQuery 3.6.0

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>
    <script src="Scripts/jquery-3.6.0.js"></script>
    <script src="Scripts/jquery-ui-1.13.1.js"></script>
    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
    <script> 
        $(function () {
            $(".date").datepicker();
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server" CssClass="date" AutoComplete="Off"></asp:TextBox>
        </div>
    </form>
</body>
</html>

測試結果



似乎正常。

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

測試

把     <script src="Scripts/jquery-ui-1.13.1.js"></script> 這行註解或砍掉,Chrome 99 上執行沒有跳出任何錯誤,只是日期不會顯示。

但是 Internet Explorer 11  ( IE11) 上顯示了錯誤。

錯誤: 物件沒有支援這個屬性或方法 'datepicker'


找到原因了,因該是之前升級 jQuery UI  時候,沒手動把
    <script src="Scripts/jquery-ui-1.12.1.js"></script>
都換成
    <script src="Scripts/jquery-ui-1.13.1.js"></script>
的原因

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

回到出事的方案,搜尋 jquery-ui-1.12.1.js 找不到,搜尋 jquery-ui 找到
App_Start\BundleConfig.cs 檔案


using System.Web.Optimization;
using System.Web.UI;

namespace PMSWeb
{
    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include(
                            "~/Scripts/WebForms/WebForms.js",
                            "~/Scripts/WebForms/WebUIValidation.js",
                            "~/Scripts/WebForms/MenuStandards.js",
                            "~/Scripts/WebForms/Focus.js",
                            "~/Scripts/WebForms/GridView.js",
                            "~/Scripts/WebForms/DetailsView.js",
                            "~/Scripts/WebForms/TreeView.js",
                            "~/Scripts/WebForms/WebParts.js"));

            // Order is very important for these files to work, they have explicit dependencies
            bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
                    "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
                    "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
                    "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
                    "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));

            // Use the Development version of Modernizr to develop with and learn from. Then, when you’re
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                            "~/Scripts/modernizr-*"));

            ScriptManager.ScriptResourceMapping.AddDefinition(
                "respond",
                new ScriptResourceDefinition
                {
                    Path = "~/Scripts/respond.min.js",
                    DebugPath = "~/Scripts/respond.js",
                });

            //string jquerystr = "3.5.1";
            string jquerystr = "3.6.0";
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
            {
                Path = "~/Scripts/jquery-" + jquerystr + ".min.js",
                DebugPath = "~/Scripts/jquery-" + jquerystr + ".js",
                CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + jquerystr + ".min.js",
                CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + jquerystr + ".js",
                CdnSupportsSecureConnection = false,
                LoadSuccessExpression = "window.jQuery"
            });

            string str = "1.12.1";
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery.ui.combined", new ScriptResourceDefinition
            {
                Path = "~/Scripts/jquery-ui-" + str + ".min.js",
                DebugPath = "~/Scripts/jquery-ui-" + str + ".js",
                CdnPath = "http://ajax.aspnetcdn.com/ajax/jquery.ui/" + str + "/jquery-ui.min.js",
                CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jquery.ui/" + str + "/jquery-ui.js",
                CdnSupportsSecureConnection = false
            });

            string bootstrapversion = "3.3.6";
            ScriptManager.ScriptResourceMapping.AddDefinition("bootstrap", new ScriptResourceDefinition()
            {
                Path = "~/Scripts/bootstrap.min.js",
                DebugPath = "~/Scripts/bootstrap.js",
                CdnPath = "http://ajax.aspnetcdn.com/ajax/bootstrap/" + bootstrapversion + "/bootstrap.min.js",
                CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/bootstrap/" + bootstrapversion + "/bootstrap.js",
                CdnSupportsSecureConnection = true,
                LoadSuccessExpression = "window.jQuery.fn.carousel"
            });
        }
    }
}

把 1.12.1 換成 1.13.1 即可。

(完)

相關

[研究]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

[研究][ASP.NET][JavaScript] jQuery datetimepicker 2.4.5 月曆套件試用(NuGet 安裝)
http://shaurong.blogspot.com/2018/03/javascript-jquery-date-and-time-picker.html

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

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

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

[jQuery] 月曆套件(一) @ 程式開發學習之路 :: 痞客邦 ::
http://pclevinblog.pixnet.net/blog/post/314562997-%5Bjquery%5D-%E6%9C%88%E6%9B%86%E5%A5%97%E4%BB%B6%28%E4%B8%80%29

2021年2月23日 星期二

[研究] 頁籤(tab) ( HTML + CSS + JavaScript + jQuery + jQuery UI)

[研究] 頁籤(tab) ( HTML + CSS + JavaScript + jQuery 3.5.1 + jQuery UI 1.12.1)

2021-02-23

參考

Tabs | jQuery UI
https://jqueryui.com/tabs/

Tabs Widget | jQuery UI 1.8 Documentation
https://api.jqueryui.com/1.8/tabs/

<meta charset="utf-8"> 這行要有,否則 Chrome 88正常,IE11 亂碼。

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery UI Tabs - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <!-- <link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css"> -->
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
        }

        table {
            font-size: 1em;
        }

        .ui-draggable, .ui-droppable {
            background-position: top;
        }
    </style>
    <!-- <script src="https://code.jquery.com/jquery-1.12.4.js"></script> -->
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
        $(function () {
            $("#tabs").tabs();
        });
    </script>
</head>
<body>

    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">頁籤1</a></li>
            <li><a href="#tabs-2">頁籤2</a></li>
            <li><a href="#tabs-3">頁籤3</a></li>
        </ul>
        <div id="tabs-1">
            <p>內容1</p>
        </div>
        <div id="tabs-2">
            <p>內容2</p>
        </div>
        <div id="tabs-3">
            <p>內容3</p>
        </div>
    </div>

</body>
</html>

(下圖) IE 11 上會出現「Internet Explorer 已限制這個網頁執行指令碼或 ActiveX 控制項。」


(下圖) IE 11 按下「允許被封鎖的內容」按鈕後。


(完)

相關

[研究] 頁籤(tab) (HTML + jQuery 3.5.1 + Bootstrap 3.4.1)
https://shaurong.blogspot.com/2021/02/tab-html-jquery-351-bootstrap-341.html

[研究] 頁籤(tab) (HTML + CSS3)
https://shaurong.blogspot.com/2021/02/tab-html-css3.html

[研究] 頁籤(tab) ( HTML + CSS + JavaScript + jQuery + jQuery UI)
https://shaurong.blogspot.com/2021/02/tab-html-css-javascript-jquery-jquery-ui.html

[研究] 頁籤(tab) (HTML+CSS+JavaScript+jQuery)
https://shaurong.blogspot.com/2021/02/tab-htmlcssjavascriptjquery.html

[研究] 頁籤(tab) (HTML+CSS+JavaScript)
https://shaurong.blogspot.com/2021/02/tab-htmlcssjavascript.html

Online HTML Code Generator | CSS Code Generator | JavaScript
https://www.html-code-generator.com/

JQuery Tabs Generator
https://www.html-code-generator.com/jquery/tabs-generator

Tabs | jQuery UI
https://jqueryui.com/tabs/

Tabs Widget | jQuery UI 1.8 Documentation
https://api.jqueryui.com/1.8/tabs/

Top Tabs Generator
https://www.pagecolumn.com/tool/top_tabs_generator.htm

Review techniques of making tabs with CSS
https://www.pagecolumn.com/webparts/making_tabs_with_CSS.htm

Tab Menu - Online Tab Menu builder
http://www.menucool.com/horizontal/tab-menu




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


2017年7月7日 星期五

[研究][ASP.NET][JavaScript] jQuery UI v1.12.1 的 Datepicker 月曆 套件 安裝與試用

[研究][ASP.NET][JavaScript] jQuery UI v1.12.1 的 Datepicker 月曆 套件 安裝與試用

2017-07-07
2018-02-07 更新

提供 Datepicker 的不只一家,例如 jQuery UI 有提供,Bootstrap 也有提供。

環境:Visual Studio 2017、C#、ASP.NET、WebForm

官方網站
https://jqueryui.com/datepicker/

Datepicker 需要 jQuery UI 套件,而 jQuery UI 套件需要 jQuery 套件。

安裝



試用

注意 jquery 的 .js要在 jquery-ui 之前。



<%@ 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>
    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.12.4.js"></script>
    <script src="Scripts/jquery-ui-1.12.1.js"></script>
    <script>
        $(function () {
            $("#TextBox1").datepicker();
        }
        );
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </div>
    </form>
</body>
</html>



執行

在TextBox中點一下,就會跳出日曆 Calendar
********************************************************************************

更方便的用法,改寫成這樣。就不需要針對每個 物件都要寫一個 Script。


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4.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>
    <script src="Scripts/jquery-1.12.4.js"></script>
    <script src="Scripts/jquery-ui-1.12.1.js"></script>
    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
    <script> 
        $(function () {
            $(".date").datepicker();
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server" CssClass="date"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server" CssClass="date"></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server" CssClass="date"></asp:TextBox>
        </div>
    </form>
</body>
</html>




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

2018-02-07 補充,再強化

<script>
        $(function () {
            $(".date").datepicker({
                 changeMonth: true,     //顯示月份下拉選單,預設是沒有
                changeYear: true,   //顯示年份下拉選單,預設是沒有
                dateFormat: 'yy/mm/dd', // 注意,是兩個y,顯示成 yyyy/mm/dd,否則預設 mm/dd/yyyy

                //showOn: "button",   // 顯示按鈕,只有點按鈕才會出現月曆,點 TextBox 無效
                //buttonImage: "./Img/calendar.gif",  // 圖片要自己另外找了放到自己想要的目錄
                //buttonImageOnly: true    // 不顯示按鈕,只顯示按鈕上的圖案
            });
        });
    </script>



**************************************
拿掉 showOn 的註解
<script>
        $(function () {
            $(".date").datepicker({
                 changeMonth: true, 
                changeYear: true,   
                dateFormat: 'yy/mm/dd', 

                showOn: "button",  
                //buttonImage: "./Img/calendar.gif",
                //buttonImageOnly: true 
            });
        });
    </script>

(下圖) 顯示按鈕,而且要按下按鈕,才會顯示月曆,現在點 TextBox 是不會顯示月曆的


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

<script>
        $(function () {
            $(".date").datepicker({
                changeMonth: true,     
                changeYear: true,   
                dateFormat: 'yy/mm/dd',  
                showOn: "button",
                buttonImage: "./Img/calendar.gif",  
                //buttonImageOnly: true   
            });
        });
    </script>

(下圖) 按鈕上有圖案了

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

<script>
        $(function () {
            $(".date").datepicker({
                changeMonth: true,     
                changeYear: true,   
                dateFormat: 'yy/mm/dd',  
                showOn: "button",
                buttonImage: "./Img/calendar.gif",  
                buttonImageOnly: true   
            });
        });
    </script>

(下圖) 不出現按鈕,只出現按鈕上的圖案

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

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>
    <link href="Content/themes/base/all.css" rel="stylesheet" />
    <script src="Scripts/jquery-3.6.0.js"></script>
    <script src="Scripts/jquery-ui-1.13.1.js"></script>
    <script type="text/javascript">
        $.datepicker.setDefaults($.datepicker.regional['zh-TW']);
        $(function () {
            var dates = $('input[class=calendar]').datepicker({
                buttonText: '月曆',
                dateFormat: 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                firstDay: 0,
                showOn: 'button'
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox_Date" runat="server" cssClass="calendar">

            </asp:TextBox>
        </div>
    </form>
</body>
</html>

結果

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

也可寫在母版 Master Page 中,不用各別 .aspx 取引用 .js 檔案,例如

Site1.Master

<%@ Master Language="C#" AutoEventWireup="true" 
    CodeBehind="Site1.master.cs" Inherits="WebApplication5.Site1" %>

<!DOCTYPE html>

<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="Scripts/jquery-3.6.0.js"></script>
    <script src="Scripts/jquery-ui-1.13.1.js"></script>
    <script type="text/javascript">
        $.datepicker.setDefaults($.datepicker.regional['zh-TW']);
        $(function () {
            var dates = $('input[class=calendar]').datepicker({
                buttonText: '日期',
                changeMonth: true,
                changeYear: true,
                firstDay: 0,
                showOn: 'button'
            });
        });
        $.timepicker.setDefaults($.datepicker.regional['zh-TW']);
        $(function () {
            var dates = $('input[class=timecalendar]').datetimepicker({
                numberOfMonths: 1,
                constrainInput: false,
                stepHour: 1,
                stepMinute: 5,
                stepSecond: 10,

                buttonText: '日期與時間',
                firstDay: 0,
                showOn: 'button',
                changeMonth: true,
                changeYear: true
            });
        });
        $(document).ready(function () {
            $('textarea').autoGrow();
            $("#footer").footer();
            $("#aspnetForm").validate();
            $('input[class=calendar]').validate();
            $('input[type=submit], button, .btnsend').button();
            $('.radio').buttonset();
            $('.checkbox').buttonset();
            $('.stars-wrapper').stars({
                cancelShow: false
            });
        });
    </script>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>

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

jQuery UI 1.13.1 時候月曆外觀改了,而且發現有重疊顯示問題,Google 說 Css 可用 

position: relative; z-index:100;

處理,但也有人說瀏覽器或某些防護會禁止用層來處理,因為某些廣告是這樣用,所以會無效。

(完)


相關

[研究]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 datetimepicker 2.4.5 月曆套件試用(NuGet 安裝)
http://shaurong.blogspot.com/2018/03/javascript-jquery-date-and-time-picker.html

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

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

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

[jQuery] 月曆套件(一) @ 程式開發學習之路 :: 痞客邦 ::
http://pclevinblog.pixnet.net/blog/post/314562997-%5Bjquery%5D-%E6%9C%88%E6%9B%86%E5%A5%97%E4%BB%B6%28%E4%B8%80%29