jQuery UI Dialog 使用詳解(1/2)

來源:互聯網
上載者:User

天用到了用戶端的對話方塊,把 jquery ui 中的對話方塊學習了一下。

準備 jquery 環境
首先,我們建立一個按鈕,點擊這個按鈕的時候,將會彈出一個對話方塊。

1 <input type="button" value="刪除" id="btn" />


 

為了設定這個按鈕點擊的事件,需要準備 jquery 的環境。

1 <script type="text/網頁特效" src="scripts/jquery-1.4.2.js"></script>
 

在 ready 中設定按鈕的點擊事件。

1 $(function() {
2    // 初始化
3    $("#btn").click(function() {
4        alert("btn 被點擊啦!");
5   }
6 );


 

確認這一步沒有問題。

 

準備對話方塊
第二步,需要準備對話方塊的內容。這些內容來自 jquery ui 的示範檔案。

 

1 <div id="dialog-confirm" title="empty the recycle bin?" >
2         <p>
3             <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
4             these items will be permanently deleted and cannot be recovered. are you sure?</p>
5 </div>

 

為了使用 jquery ui 的對話方塊,需要增加這些檔案的引用。

1 <script type="text/javascript" src="scripts/jquery.ui.core.js"></script>
2 <script type="text/javascript" src="scripts/jquery.ui.widget.js"></script>
3 <script type="text/javascript" src="scripts/jquery.ui.mouse.js"></script>
4 <script type="text/javascript" src="scripts/jquery.ui.button.js"></script>
5 <script type="text/javascript" src="scripts/jquery.ui.draggable.js"></script>
6 <script type="text/javascript" src="scripts/jquery.ui.position.js"></script>
7 <script type="text/javascript" src="scripts/jquery.ui.dialog.js"></script>

 

增加樣式

jquery ui 中使用了大量的樣式來修飾,需要引用 jquery ui 的樣式,注意,jquery.ui.all.css教程 這個檔案引用了大量的其他樣式檔案,將 jquery ui 中 development-bundlethemesbase 檔案夾中的內容都複製過來。

1 <link type="text/css" href="styles/jquery.ui.all.css" rel="stylesheet" />
在 ready 函數中,同時也初始化這個對話方塊。

1 $(function() {
2     // 初始化
3     $("#btn").click(function() {
4         alert("btn 被點擊啦!");
5     });
6
7     // 初始化對話方塊
8     $("#dialog-confirm").dialog();
9 });


 

現在,開啟這個頁面的時候,就已經可以看到對話方塊了。

 

首頁 1 2 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.