欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery獲取各種寬度、高度(format函數(shù))實例

 更新時間:2013年03月04日 11:37:52   作者:  
本例除了使用標準的JQuery類庫外,還添加了自定義的函數(shù)來進行字符串的format操作。

復制代碼 代碼如下:

<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>

相關(guān)文章

最新評論