移动网站开发中常用的JavaScript代码有哪些
发表于:2025-11-10 作者:千家信息网编辑
千家信息网最后更新 2025年11月10日,本篇内容介绍了"移动网站开发中常用的JavaScript代码有哪些"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能
千家信息网最后更新 2025年11月10日移动网站开发中常用的JavaScript代码有哪些
'; output += ' '; $('#mylistul').append(output).listview('refresh');
本篇内容介绍了"移动网站开发中常用的JavaScript代码有哪些"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1、如果网页是在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、防止网页触摸滚动
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 += ''; } $('.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、从列表视图的链接中删除活动状态(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、动态更新列表视图(jQuery mobile)
var output = '
' + item.title + '
'; output += '10、动态添加表单输入和应用默认样式(jQuery mobile)
var html = ''; $('#searchform').append(html); $('#suburb').textinput();"移动网站开发中常用的JavaScript代码有哪些"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
网站
信息
浏览
代码
常用
网站开发
开发
移动
内容
动态
更多
样式
浏览器
知识
网页
视图
时显
实用
成功
学有所成
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
学校网络安全风险防范化解
套接字服务器
php 查看服务器信息
dell r720服务器内存条
服务器主板重复开机时间短
三门峡网络技术优化平台
网络安全大字手写
mysql数据库小数点
lol是什么软件开发的
科技成果数据库
中国经纬度海拔数据库
互联网智慧驿站优智科技
软件开发flux工具
湖南仓储系统管理软件开发
数据库当前日期往后推两周
网络技术高手如何在网络上赚钱
无线电网络技术及其应用课件
庐阳区网络技术开发常见问题
试述关系数据库管理
2019数字中国网络安全
饭圈网络安全画
静安区营销软件开发制造价格
浪潮服务器无法识别光盘
数据库中软件设计原则
国开行苏州软件开发中心招聘
女孩子转软件开发
科技成果数据库
兰溪市蜂巢网络技术有限公司
万有网络技术待遇
手机打开服务器拒绝连接怎么办