
代码如下:
获取页面宽度 script>
$.format = function (source, params) {
if (arguments.length == 1)
return function () {
var args = $.makeArray(arguments);
args.unshift(source);
return $.format.apply(this, args);
};
if (arguments.length > 2 && params.constructor != Array) {
params = $.makeArray(arguments).slice(1);
}
if (params.constructor != Array) {
params = [params];
}
$.each(params, function (i, n) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
});
return source;
};
/*------------以上是字符串format函数----------------*/
$(document).ready(function () {
$("button").click(function () {
var d=$("#div1");
var txt = "";
txt += $.format("width(): {0}", d.width());
txt += $.format("height(): {0}", d.height());
txt += $.format("Inner Width: {0}", d.innerWidth());
txt += $.format("Inner Height: {0}", d.innerHeight());
txt += $.format("Outer Width: {0}", d.outerWidth());
txt += $.format("Outer Height: {0}", d.outerHeight());
txt += $.format("outerWidth(true): {0}", d.outerWidth(true));
txt += $.format("outerHeight(true): {0}", d.outerHeight(true));
txt += $.format("HTML文档宽度: {0}", $(document).width());
txt += $.format("HTML文档高度: {0}", $(document).height());
txt += $.format("浏览器视口宽度: {0}", $(window).width());
txt += $.format("浏览器视口高度: {0}", $(window).height());
$("#div1").html(txt);
});
});
script>
手机话费、Q币、游戏充值
width() - 返回元素的宽度。
height() - 返回元素的高度。
innerWidth() 方法返回元素的宽度(包括内边距)。
innerHeight() 方法返回元素的高度(包括内边距)。
outerWidth() 方法返回元素的宽度(包括内边距和边框)。
outerHeight() 方法返回元素的高度(包括内边距和边框)。
outerWidth(true) 方法返回元素的宽度(包括内边距、边框和外边距)。
outerHeight(true) 方法返回元素的高度(包括内边距、边框和外边距)。
返回文档(HTML 文档)$(document).height()的高度
返回窗口(浏览器视口)$(window).height()的高度