jquery gets various width, height (format function) instances _jquery

Source: Internet
Author: User

Copy Code code as follows:

<title> Get page Width </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;
};
/*------------above is the string format function----------------* *
$ (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 Document Width: {0}</br>", $ (document). width ());
TXT + $.format ("HTML Document Height: {0}</br>", $ (document). Height ());
txt = $.format ("Browser viewport width: {0}</br>", $ (window). width ());
txt = $.format ("Browser height: {0}</br>", $ (window). Height ());
$ ("#div1"). HTML (TXT);
});
});
</script>
<body>

<div id= "Div1" style= "height:auto;width:300px;padding:10px;margin:3px;border:1px solid Blue;background-color: LightBlue; " ></div>
<br/>
<button> Display current various sizes </button>
<p><a href= "http://4welove.taobao.com" target= "_blank" > Mobile phone bill, Q currency, game recharge </a></p>
<p>width ()-Returns the width of the element. </p>
<p>height ()-Returns the height of the element. </p>
The <p>innerwidth () method returns the width of the element, including the inner margin. </p>
The <p>innerheight () method returns the height of the element, including the inner margin. </p>
The <p>outerwidth () method returns the width of the element (including the inner margin and border). </p>
The <p>outerheight () method returns the height of the element (including the inner margin and border). </p>
The <p>outerwidth (True) method returns the width of the element, including the inner margin, border, and outer margin. </p>
The <p>outerheight (True) method returns the height of the element, including the inner margin, border, and outer margin. </p>
<p> Return Documents (HTML documents) $ (document). Height () high </p>
<p> return window (browser viewport) $ (window). Height () </p>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.