成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

移動(dòng)網(wǎng)站開發(fā)中常用的10段JavaScript代碼

開發(fā) 前端
移動(dòng)網(wǎng)站開發(fā)中常用的10段JavaScript代碼,趕快收藏吧!

1、如果網(wǎng)頁是在iPhone或Android瀏覽器中查看,則在主體元素中添加“iPhone”或“Android” 類名

  1. if (navigator.userAgent.match(/iPhone/i)) {  
  2.     $('body').addClass('iPhone');  
  3. } else if (navigator.userAgent.match(/Android/i)) {  
  4.         $('body').addClass('Android');  

iPhone用戶瀏覽示例:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A537a Safari/419.3
Mozilla/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A477d Safari/419.3

Android用戶瀏覽示例:

Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 1.6; en-gb; Dell Streak Build/Donut AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/ 525.20.1
Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17
Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 2.2; en-gb; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; E10i Build/2.0.2.A.0.24) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17

2、移除瀏覽器地址欄

  1. window.scrollTo(0, 1); 

3、防止網(wǎng)頁觸摸滾動(dòng)

  1. notouchmove = function(event) {  
  2.     event.preventDefault();  
  3. }  
  4. <div data-role="page" id="home" ontouchmove="notouchmove(event);">  
  5. ...  
  6. </div> 

4、當(dāng)橫向?yàn)g覽時(shí)顯示信息

  1. var updateorientation = function (){  
  2.     var classname = '',  
  3.     top = 100;  
  4.     switch(window.orientation){  
  5.         case 0:  
  6.         classname += "normal";  
  7.         break;  
  8.  
  9.         case -90:  
  10.         classname += "landscape";  
  11.         break;  
  12.  
  13.         case 90:  
  14.         classname += "landscape";  
  15.         break;  
  16.  
  17.     }  
  18.  
  19.     if (classname == 'landscape') {  
  20.         if ($('#overlay').length === 0) {  
  21.             window.scrollTo(0, 1);  
  22.             $('body').append('<div id="overlay" style="width: 100%; height:' + $(document).height() + 'px"><span style="top: ' + top + 'px">Landscape view is not supported for this page.</span></div>');  
  23.         }  
  24.     } else {  
  25.         $('#overlay').remove();  
  26.     }  
  27. };  
  28. Usage:  
  29.  
  30. var supportsOrientationChange = "onorientationchange" in window,  
  31. orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";  
  32.  
  33. window.addEventListener(orientationEvent, function() {  
  34.     updateorientation();  
  35. }, false); 

5、顯示部分描述信息,當(dāng)點(diǎn)擊時(shí)顯示完整信息

  1. var truncatedesc = function(trunc, len) {  
  2.     if (trunc) {  
  3.       var org = trunc;  
  4.  
  5.       if (trunc.length > len) {  
  6.         trunc = trunc.substring(0, len);  
  7.         trunc = trunc.replace(/w+$/, '');  
  8.  
  9.         trunc = '<span class="truncated">' + trunc;  
  10.         trunc += '<strong class="more-description">...</strong></span>';  
  11.         trunc += '<span class="original" style="display: none;">' + org + '</span>';  
  12.       }  
  13.  
  14.       $('.truncated').live("touchstart touchend"function() {  
  15.         $(this).closest('div').find('.original').show();  
  16.         $(this).closest('div').find('.truncated').hide();  
  17.         return false;  
  18.       });  
  19.  
  20.       return trunc;  
  21.     }  
  22. };  
  23.  
  24. Usage:  
  25.  
  26. truncatedesc(item.description, 100); 

6、收到成功的Ajax請(qǐng)求時(shí),重定向到另一個(gè)頁面(jQuery mobile)

  1. var ajaxurl = ‘http://…’; // Your web service URL  
  2.  
  3. $.ajax({  
  4.     url: ajaxurl,  
  5.     type: 'GET',  
  6.     processData: false,  
  7.     contentType: "application/json",  
  8.     dataType: "jsonp",  
  9.     success: function(data) {  
  10.         $.mobile.changePage("results.html");  
  11.     },  
  12.     error: function() {  
  13.         alert('Error!');  
  14.     }  
  15. }); 

7、從列表視圖的鏈接中刪除活動(dòng)狀態(tài)(jQuery mobile)

  1. $('div').live('pageshow'function (event, ui) {  
  2.     $('[data-role=listview] li').removeClass("ui-btn-active");  
  3. }); 

8、從下拉選擇中禁用默認(rèn)的jQuery mobile樣式(jQuery mobile)

  1. $(document).bind("mobileinit"function(){  
  2.      $.mobile.page.prototype.options.keepNative = "select";  
  3. }); 

9、動(dòng)態(tài)更新列表視圖(jQuery mobile)

  1. var output  = '<li><img src="' + item.image + '" alt="' + item.title + '" />';  
  2. output += '<h3><a href="' + item.url + '">' + item.title + '</a></h3>';  
  3. output += '</li>';     
  4.  
  5. $('#mylistul').append(output).listview('refresh');  

10、動(dòng)態(tài)添加表單輸入和應(yīng)用默認(rèn)樣式(jQuery mobile)

  1. var html = '<input type="search" name="suburb" id="suburb" placeholder="Enter suburb" />';  
  2. $('#searchform').append(html);  
  3. $('#suburb').textinput(); 

原文:http://qing.weibo.com/1609119537/5fe93731330004ep.html

【編輯推薦】

  1. Google推出JavaScript測試工具Google JS Test
  2. 淺談JavaScript編程語言的編碼規(guī)范
  3. 9月Web技術(shù)最前沿:jQuery成版本帝
  4. 如今的開發(fā)者應(yīng)了解哪些過去聞所未聞的新技能
  5. 當(dāng)jQuery遭遇CoffeeScript——妙不可言
責(zé)任編輯:陳貽新 來源: 2gua
相關(guān)推薦

2011-05-12 17:26:40

移動(dòng)網(wǎng)站CSS

2011-05-12 17:13:06

移動(dòng)網(wǎng)站標(biāo)記語言

2012-02-16 10:39:12

Android版Chr移動(dòng)網(wǎng)站開發(fā)者

2012-03-06 16:57:40

jQuery mobijQuery mobiframework

2013-08-20 14:13:01

網(wǎng)站開發(fā)編程

2009-07-01 16:54:20

JSP網(wǎng)站開發(fā)教程

2011-07-07 10:10:02

WEB

2014-05-04 11:06:41

移動(dòng)網(wǎng)站移動(dòng)設(shè)計(jì)

2009-05-18 16:59:42

代碼PHP編碼

2011-05-18 13:47:32

2013-08-29 10:50:48

移動(dòng)網(wǎng)站性能優(yōu)化移動(dòng)web

2019-06-21 10:13:26

JavaScript錯(cuò)誤開發(fā)

2013-08-27 13:13:29

移動(dòng)網(wǎng)站性能優(yōu)化移動(dòng)web

2011-03-22 10:03:24

web網(wǎng)站開發(fā)

2023-07-04 07:31:12

JavaScriptWeb

2009-06-01 11:16:48

PHP網(wǎng)站開發(fā)變量作用域

2009-11-27 11:08:11

PHP動(dòng)態(tài)網(wǎng)站開發(fā)

2020-08-04 06:32:21

JavaScript代碼開發(fā)

2019-07-02 10:36:30

JavaScript硬件開發(fā)

2012-02-27 14:52:33

網(wǎng)站
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 国产一区二区三区四区 | jizz中国日本| 日韩在线看片 | 91xxx在线观看| 91精品久久久 | 青青久在线视频 | 欧美一区2区三区3区公司 | 你懂的在线视频播放 | 国产精品成人69xxx免费视频 | 超碰精品在线 | 亚洲精品久久久久久宅男 | 爱爱免费视频 | 精品中文字幕久久 | 久久久久久99 | 成人教育av| 欧美性久久| 久久精品高清视频 | 天天插天天操 | 久久精品视频在线免费观看 | 久久99深爱久久99精品 | 97超碰免费| 91亚洲精 | 国产免费拔擦拔擦8x高清 | 亚洲精品区 | 国产区一区 | 亚洲一二三视频 | 97av视频| 日本视频一区二区三区 | 日日夜夜免费精品视频 | 欧美性生活一区二区三区 | 国产精品国产精品国产专区不卡 | 久久久久亚洲精品 | 国产95在线 | 久草在线免费资源 | 国产精品视频一区二区三 | 中文字幕一区在线 | 国产极品粉嫩美女呻吟在线看人 | 日韩一区二区三区四区五区六区 | 成人性生交大片免费看中文带字幕 | 精品视频一区二区 | 亚洲精品在线免费观看视频 |