JQuery獲取各種寬度、高度(format函數(shù))實例
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>獲取頁面寬度</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.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函數(shù)----------------*/
$(document).ready(function () {
$("button").click(function () {
var d=$("#div1");
var txt = "";
txt += $.format("width(): {0}</br>", d.width());
txt += $.format("height(): {0}</br>", d.height());
txt += $.format("Inner Width: {0}</br>", d.innerWidth());
txt += $.format("Inner Height: {0}</br>", d.innerHeight());
txt += $.format("Outer Width: {0}</br>", d.outerWidth());
txt += $.format("Outer Height: {0}</br>", d.outerHeight());
txt += $.format("outerWidth(true): {0}</br>", d.outerWidth(true));
txt += $.format("outerHeight(true): {0}</br>", d.outerHeight(true));
txt += $.format("HTML文檔寬度: {0}</br>", $(document).width());
txt += $.format("HTML文檔高度: {0}</br>", $(document).height());
txt += $.format("瀏覽器視口寬度: {0}</br>", $(window).width());
txt += $.format("瀏覽器視口高度: {0}</br>", $(window).height());
$("#div1").html(txt);
});
});
</script>
</head>
<body>
<div id="div1" style="height:auto;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
<br/>
<button>顯示當前各種尺寸</button>
<p><a target="_blank">手機話費、Q幣、游戲充值</a></p>
<p>width() - 返回元素的寬度。</p>
<p>height() - 返回元素的高度。</p>
<p>innerWidth() 方法返回元素的寬度(包括內(nèi)邊距)。 </p>
<p>innerHeight() 方法返回元素的高度(包括內(nèi)邊距)。 </p>
<p>outerWidth() 方法返回元素的寬度(包括內(nèi)邊距和邊框)。 </p>
<p>outerHeight() 方法返回元素的高度(包括內(nèi)邊距和邊框)。 </p>
<p>outerWidth(true) 方法返回元素的寬度(包括內(nèi)邊距、邊框和外邊距)。 </p>
<p>outerHeight(true) 方法返回元素的高度(包括內(nèi)邊距、邊框和外邊距)。 </p>
<p>返回文檔(HTML 文檔)$(document).height()的高度</p>
<p>返回窗口(瀏覽器視口)$(window).height()的高度</p>
</body>
</html>
- jquery實現(xiàn)動態(tài)改變div寬度和高度
- jquery動態(tài)改變div寬度和高度
- 基于jQuery實現(xiàn)左右div自適應高度完全相同的代碼
- js/jquery獲取瀏覽器窗口可視區(qū)域高度和寬度以及滾動條高度實現(xiàn)代碼
- js和jquery如何獲取圖片真實的寬度和高度
- JQuery獲取當前屏幕的高度寬度的實現(xiàn)代碼
- JS和jquery獲取各種屏幕的寬度和高度的代碼
- 使用jquery獲取網(wǎng)頁中圖片高度的兩種方法
- JQuery獲取瀏覽器窗口內(nèi)容部分高度的代碼
- jQuery獲取頁面及個元素高度、寬度的總結(jié)——超實用
- jquery實現(xiàn)在頁面加載完畢后獲取圖片高度或?qū)挾?/a>
- jquery獲取文檔高度和窗口高度匯總
- jQuery實現(xiàn)獲取隱藏div高度的方法示例
相關(guān)文章
jQuery EasyUI API 中文文檔 - ComboBox組合框
jQuery EasyUI API 中文文檔 - ComboBox組合框,使用jQuery EasyUI的朋友可以參考下。2011-10-10HTML5+jQuery插件Quicksand實現(xiàn)超酷的星際爭霸2兵種分類展示效果(附demo源碼下載)
這篇文章主要介紹了HTML5+jQuery插件Quicksand實現(xiàn)超酷的星際爭霸2兵種分類展示效果,詳細分析了Quicksand插件的使用及圖片浮動顯示的實現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-05-05jQuery?UI旋轉(zhuǎn)器部件Spinner?Widget
這篇文章介紹了jQuery?UI旋轉(zhuǎn)器部件Spinner?Widget,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-06-06在瀏覽器中實現(xiàn)圖片粘貼的jQuery插件-- pasteimg使用指南
這篇文章主要介紹了在瀏覽器中實現(xiàn)圖片粘貼的jQuery插件-- pasteimg使用指南,需要的朋友可以參考下2014-12-12