手机日期插件jquery mobiscroll 实例

net视图引擎可直接渲染mobiscroll控件

 

  1. @using (Html.BeginForm())  
  2. {  
  3.     @Html.LabelFor(m => m.Name)  
  4.     @Html.TextBoxFor(m => m.Name)  
  5.     <br />  
  6.     @Html.LabelFor(m => m.Birthday)  
  7.   
  8.     <!-- Generate a date scroller for the birthday model property-->  
  9.     @Html.Mobiscroll().DateFor(m => m.Birthday)  
  10.     <br />  
  11.     @Html.LabelFor(m => m.Gender)  
  12.   
  13.     <!-- create the selectlist used for the select scroller -->  
  14.     IEnumerable<SelectListItem> genders = new SelectList(new List<string>(){"male", "female"});  
  15.     @Html.Mobiscroll().SelectFor(m => m.Gender, genders)  
  16.     <br />  
  17.     @Html.LabelFor(m => m.FavoriteBook)  
  18.   
  19.     <!-- create the selectlist for the books grouped by author -->  
  20.     Dictionary<string, IEnumerable<SelectListItem>> books = new Dictionary<string, IEnumerable<SelectListItem>>();  
  21.     books.Add("Adams", new SelectList(new List<string>() {   
  22.         "The Hitchhiker's Guide to the Galaxy",   
  23.         "The Restaurant at the End of the Universe",   
  24.         "So Long, and Thanks for All the Fish",   
  25.         "Life, the Universe and Everything"   
  26.     }));  
  27.     books.Add("Asimov", new SelectList(new List<string>() {   
  28.         "I, Robot",   
  29.         "The Caves of Steel",   
  30.         "Foundation"   
  31.     }));  
  32.     books.Add("Herbert", new SelectList(new List<string>() {   
  33.         "Dune",   
  34.         "God Emperor of Dune",   
  35.         "Dune Messiah",   
  36.         "Children of Dune"   
  37.     }));  
  38.     @Html.Mobiscroll().SelectFor(m => m.FavoriteBook, books)  
  39.     <br />  
  40.     <button type="submit">Send</button>  
  41. }  
  42.        


详情:http://docs.mobiscroll.com/2-14-3/mvc-helpers

 

 

以下是本人看了一下API后随意写的几个例子,其实用select去做会更好,此处只是演示,就随便啦!

 

自定义年月(去掉年月日的"日"滚轮布局):

 

  1. @{  
  2.     ViewBag.Title = "taste mobiscroll";  
  3. }  
  4. @section styles{  
  5. <link href="~/Content/mobiscroll-2.13.2.full.min.css" rel="stylesheet" />  
  6. <style>  
  7. </style>  
  8. }  
  9. <div class="container">  
  10.     <input id="date" />  
  11. </div>  
  12.   
  13. @section scripts{  
  14. <script src="~/Scripts/jquery-1.8.2.min.js"></script>  
  15. <script src="~/Scripts/mobiscroll-2.13.2.full.min.js"></script>     
  16. <script>  
  17. $(function () {  
  18.     $("#date").mobiscroll().date({  
  19.         theme: "android-ics light",  
  20.         lang: "zh",  
  21.         cancelText: null,  
  22.         dateFormat: 'yy/mm', //返回结果格式化为年月格式  
  23.         // wheels:[], 设置此属性可以只显示年月,此处演示,就用下面的onBeforeShow方法,另外也可以用treelist去实现  
  24.         onBeforeShow: function (inst) { inst.settings.wheels[0].length>2?inst.settings.wheels[0].pop():null; }, //弹掉“日”滚轮  
  25.         headerText: function (valueText) { //自定义弹出框头部格式  
  26.             array = valueText.split('/');  
  27.             return array[0] + "年" + array[1] + "月";  
  28.         }  
  29.     });  
  30. })   
  31. </script>  
  32. }  

效果如下图:

 

treelist 示例一:

 

  1. <style>  
  2. .mbsc-android-holo .dwv { text-align:left;text-indent:.8em; }  
  3. </style>  
  4.   
  5. <ul id="treelist">  
  6.     <li>普通班</li><li>VIP班</li><li>特色班</li><li>至尊班</li><li>女子特训班</li>  
  7. </ul>  
  8.   
  9. <script>  
  10. $(function () {  
  11.     $("#treelist").mobiscroll().treelist({  
  12.         theme: "android-ics light",  
  13.         lang: "zh",  
  14.         defaultValue: [Math.floor($('#treelist li').length/2)],  
  15.         cancelText: null,  
  16.         headerText: function (valueText) { return "选择班级"; }  
  17.     });  
  18. })   
  19. </script>  


效果如下图:

 

 

treelist 示例二:

 

  1. <style>  
  2. .mbsc-android-holo .dwv { text-align:left;text-indent:.8em; }  
  3. </style>  
  4.   
  5. <ul id="treelist">  
  6.     <li>  
  7.         <span>奥迪</span>  
  8.         <ul>  
  9.             <li>奥迪A3</li>  
  10.             <li>奥迪A4L</li>  
  11.             <li>奥迪A6L</li>  
  12.             <li>奥迪Q3</li>  
  13.             <li>奥迪Q5</li>  
  14.             <li>奥迪A4</li>  
  15.             <li>奥迪A6</li>  
  16.             <li>奥迪A1</li>  
  17.             <li>奥迪A3(进口)</li>  
  18.         </ul>  
  19.     </li>  
  20.     <li>  
  21.         <span>宝马</span>  
  22.         <ul>  
  23.             <li>宝马X1</li>  
  24.             <li>宝马i3</li>  
  25.             <li>宝马1系</li>  
  26.             <li>宝马3系</li>  
  27.             <li>宝马5系</li>  
  28.         </ul>  
  29.     </li>  
  30.     <li>  
  31.         <span>奔驰</span>  
  32.         <ul>  
  33.             <li>奔驰A级</li>  
  34.             <li>奔驰C级</li>  
  35.             <li>奔驰E级</li>  
  36.             <li>奔驰S级</li>  
  37.             <li>奔驰GLK级</li>  
  38.             <li>奔驰CLA级</li>  
  39.             <li>奔驰CLS级</li>  
  40.         </ul>  
  41.     </li>  
  42. </ul>  
  43.   
  44. <script>  
  45. $(function () {  
  46.     var i = Math.floor($('#treelist>li').length / 2),  
  47.         j = Math.floor($('#treelist>li').eq(i).find('ul li').length / 2);  
  48.     $("#treelist").mobiscroll().treelist({  
  49.         theme: "android-ics light",  
  50.         lang: "zh",  
  51.         defaultValue: [i,j],  
  52.         cancelText: null,  
  53.         placeholder: '选择车型',  
  54.         headerText: function (valueText) { return "选择车型"; },  
  55.         formatResult: function (array) { //返回自定义格式结果  
  56.             return $('#treelist>li').eq(array[0]).children('span').text() +' '+ $('#treelist>li').eq(array[0]).find('ul li').eq(array[1]).text().trim(' ');  
  57.         }  
  58.     });  
  59. })   
  60. </script>  


效果如图:

 

分类:  JQuery
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值