本篇內(nèi)容介紹了“移動網(wǎng)站開發(fā)中常用的JavaScript代碼有哪些”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供青原網(wǎng)站建設(shè)、青原做網(wǎng)站、青原網(wǎng)站設(shè)計、青原網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、青原企業(yè)網(wǎng)站模板建站服務(wù),10余年青原做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
1、如果網(wǎng)頁是在iPhone或Android瀏覽器中查看,則在主體元素中添加“iPhone”或“Android” 類名
if (navigator.userAgent.match(/iPhone/i)) { $('body').addClass('iPhone'); } else if (navigator.userAgent.match(/Android/i)) { $('body').addClass('Android'); }
2、移除瀏覽器地址欄
window.scrollTo(0, 1);
3、防止網(wǎng)頁觸摸滾動
notouchmove = function(event) { event.preventDefault(); } <div data-role="page" id="home" ontouchmove="notouchmove(event);"> ... </div>
4、當(dāng)橫向瀏覽時顯示信息
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('<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>'); } } else { $('#overlay').remove(); } }; Usage: var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; window.addEventListener(orientationEvent, function() { updateorientation(); }, false);
5、顯示部分描述信息,當(dāng)點擊時顯示完整信息
var truncatedesc = function(trunc, len) { if (trunc) { var org = trunc; if (trunc.length > len) { trunc = trunc.substring(0, len); trunc = trunc.replace(/w+$/, ''); trunc = '<span class="truncated">' + trunc; trunc += '<strong class="more-description">...</strong></span>'; trunc += '<span class="original" style="display: none;">' + org + '</span>'; } $('.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、從下拉選擇中禁用默認(rèn)的jQuery mobile樣式(jQuery mobile)
$(document).bind("mobileinit", function(){ $.mobile.page.prototype.options.keepNative = "select"; });
9、動態(tài)更新列表視圖(jQuery mobile)
var output = '<li><img src="' + item.image + '" alt="' + item.title + '" />'; output += '<h4><a href="' + item.url + '">' + item.title + '</a></h4>'; output += '</li>'; $('#mylistul').append(output).listview('refresh');
10、動態(tài)添加表單輸入和應(yīng)用默認(rèn)樣式(jQuery mobile)
var html = '<input type="search" name="suburb" id="suburb" placeholder="Enter suburb" />'; $('#searchform').append(html); $('#suburb').textinput();
“移動網(wǎng)站開發(fā)中常用的JavaScript代碼有哪些”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
文章標(biāo)題:移動網(wǎng)站開發(fā)中常用的JavaScript代碼有哪些
網(wǎng)站URL:http://jinyejixie.com/article24/ggepce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站建設(shè)、ChatGPT、靜態(tài)網(wǎng)站、移動網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)