jquery mobile 實現自訂confirm確認框效果

來源:互聯網
上載者:User

標籤:

類似刪除的效果,在執行之前,一般需要添加確認對話方塊,點確認的話執行,取消按鈕就不執行,傳統的js

if(confirm(‘確定刪除嗎?‘))

{

//執行代碼

}

這種效果比較醜,使用jquery mobile最佳化一下

需要引用的檔案:

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Scripts/Mobile/jquery.mobile-1.4.0.min.css" rel="stylesheet" />
<script src="~/Scripts/Mobile/jquery.mobile-1.4.0.min.js"></script>

效果如下:

 1 function UpdateStatus() { 2     var popupDialogId = ‘popupDialog‘; 3     $(‘<div data-role="popup" id="‘ + popupDialogId + ‘" data-confirmed="no" data-transition="pop" data-overlay-theme="b" data-theme="b" data-dismissible="false" style="min-width:216px;max-width:500px;">  4                      5                     <div role="main" class="ui-content"> 6                         <h3 class="ui-title" style="color:#fff; text-align:center;margin-bottom:15px">確認關閉任務嗎?</h3> 7                         <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b optionConfirm" data-rel="back" style="background: #1784fd;width: 33%;border-radius: 5px;height: 30px;line-height: 30px;padding: 0;font-size: .9em;margin: 0 0 0 12%;font-weight: 100;">確定</a> 8                         <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b optionCancel" data-rel="back" data-transition="flow" style="background: #DBDBDB;width: 33%;border-radius: 5px;height: 30px;line-height: 30px;padding: 0;font-size: .9em;margin: 0 0 0 5%;font-weight: 100;color: #333;text-shadow: none;">取消</a> 9                     </div>10                 </div>‘)11         .appendTo($.mobile.pageContainer);12     var popupDialogObj = $(‘#‘ + popupDialogId);13     popupDialogObj.trigger(‘create‘);14     popupDialogObj.popup({15         afterclose: function (event, ui) {16             popupDialogObj.find(".optionConfirm").first().off(‘click‘);17             var isConfirmed = popupDialogObj.attr(‘data-confirmed‘) === ‘yes‘ ? true : false;18             $(event.target).remove();19             if (isConfirmed) {20                //這裡執行確認需要執行的代碼21             }22         }23     });24     popupDialogObj.popup(‘open‘);25     popupDialogObj.find(".optionConfirm").first().on(‘click‘, function () {26         popupDialogObj.attr(‘data-confirmed‘, ‘yes‘);27     });28 }

 

分享兩個擷取汽車品牌資料的地址:

XCAR的

http://html.xcar.com.cn/newcar/pub_js/car_arr_newcar_2009_ps.js

AUTOHOME的 

http://www.autohome.com.cn/ashx/AjaxIndexCarFind.ashx?type=1

或者

http://www.autohome.com.cn/ashx/AjaxIndexCarFind.ashx?type=11

擷取品牌列表,然後

http://www.autohome.com.cn//ashx/AjaxIndexCarFind.ashx?type=3&value=3

擷取車型列表(例子中的value=3對應豐田)。

 具體的還可以查在售、停售、即將上市等,可以去AUTOHOME看源碼。

jquery mobile 實現自訂confirm確認框效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.