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

成都創(chuàng)新互聯(lián)服務(wù)項目包括河曲網(wǎng)站建設(shè)、河曲網(wǎng)站制作、河曲網(wǎng)頁制作以及河曲網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,河曲網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到河曲省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
- if (navigator.userAgent.match(/iPhone/i)) {
- $('body').addClass('iPhone');
- } else if (navigator.userAgent.match(/Android/i)) {
- $('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、移除瀏覽器地址欄
- window.scrollTo(0, 1);
3、防止網(wǎng)頁觸摸滾動
- notouchmove = function(event) {
- event.preventDefault();
- }
- ...
4、當橫向瀏覽時顯示信息
- var updateorientation = function (){
- var classname = '',
- top = 100;
- switch(window.orientation){
- case 0:
- classname += "normal";
- break;
- case -90:
- classname += "landscape";
- break;
- case 90:
- classname += "landscape";
- break;
- }
- if (classname == 'landscape') {
- if ($('#overlay').length === 0) {
- window.scrollTo(0, 1);
- $('body').append('
Landscape view is not supported for this page.');- }
- } else {
- $('#overlay').remove();
- }
- };
- Usage:
- var supportsOrientationChange = "onorientationchange" in window,
- orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
- window.addEventListener(orientationEvent, function() {
- updateorientation();
- }, false);
5、顯示部分描述信息,當點擊時顯示完整信息
- var truncatedesc = function(trunc, len) {
- if (trunc) {
- var org = trunc;
- if (trunc.length > len) {
- trunc = trunc.substring(0, len);
- trunc = trunc.replace(/w+$/, '');
- trunc = '' + trunc;
- trunc += '...';
- trunc += '' + org + '';
- }
- $('.truncated').live("touchstart touchend", function() {
- $(this).closest('div').find('.original').show();
- $(this).closest('div').find('.truncated').hide();
- return false;
- });
- return trunc;
- }
- };
- Usage:
- truncatedesc(item.description, 100);
6、收到成功的Ajax請求時,重定向到另一個頁面(jQuery mobile)
- var ajaxurl = ‘http://…’; // Your web service URL
- $.ajax({
- url: ajaxurl,
- type: 'GET',
- processData: false,
- contentType: "application/json",
- dataType: "jsonp",
- success: function(data) {
- $.mobile.changePage("results.html");
- },
- error: function() {
- alert('Error!');
- }
- });
7、從列表視圖的鏈接中刪除活動狀態(tài)(jQuery mobile)
- $('div').live('pageshow', function (event, ui) {
- $('[data-role=listview] li').removeClass("ui-btn-active");
- });
8、從下拉選擇中禁用默認的jQuery mobile樣式(jQuery mobile)
- $(document).bind("mobileinit", function(){
- $.mobile.page.prototype.options.keepNative = "select";
- });
9、動態(tài)更新列表視圖(jQuery mobile)
- var output = '
';
- output += '
' + item.title + '
';- output += '
';- $('#mylistul').append(output).listview('refresh');
10、動態(tài)添加表單輸入和應(yīng)用默認樣式(jQuery mobile)
- var html = '';
- $('#searchform').append(html);
- $('#suburb').textinput();
原文:http://qing.weibo.com/1609119537/5fe93731330004ep.html
分享題目:移動網(wǎng)站開發(fā)中常用的10段JavaScript代碼
URL網(wǎng)址:http://fisionsoft.com.cn/article/cccoodc.html


咨詢
建站咨詢
