最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

復(fù)制代碼 代碼如下:

<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>顯示當(dāng)前各種尺寸</button>
    <p><a target="_blank">手機(jī)話費(fèi)、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)文章

最新評(píng)論

普兰店市| 广汉市| 梓潼县| 楚雄市| 久治县| 白银市| 固阳县| 内乡县| 潜江市| 张家港市| 上饶市| 新巴尔虎右旗| 商丘市| 包头市| 佛坪县| 双流县| 扬中市| 离岛区| 五家渠市| 新民市| 鲁甸县| 瓮安县| 衢州市| 洛扎县| 镇赉县| 溧阳市| 达孜县| 固阳县| 高安市| 桑日县| 秦皇岛市| 广水市| 汉中市| 阜平县| 定结县| 科技| 米脂县| 库伦旗| 平邑县| 浦县| 锦屏县|