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 += '' + 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、从列表视图的链接中删除活动状态(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 = '
';
output += '';
output += '';
$('#mylistul').append(output).listview('refresh');
10、动态添加表单输入和应用默认样式(jQuery mobile)
var html = '';
$('#searchform').append(html);
$('#suburb').textinput();