Check the image size in Javascript.

Source: Internet
Author: User

Check the image size in Javascript.

You only need to write a simple function to determine the image size using Javascript. Of course, many people may not know how to write this function. I found that using ASP to determine the image size is more complicated than that of taobaomao. When I judge the image size, I still need to display it logically... Annoying. It is easy to use Javascript to judge and solve the problem. The final effect is nothing more than making large images break the page.

<Script LANGUAGE = "JAVASCRIPT"> // check whether the image size is greater than the expected size. If the image size is greater than the expected size, function show (chkw) {// chk images widthif (chkw> 500) is displayed) {chkw = 500;} else {chkw = chkw;} return chkw;} // shawl. qiu script // example  </script> 1. check box automatically selected by mouse: <input TYPE = "checkbox" onMouseMove = "checked = true"> <input TYPE = "checkbox" onMouseMove = "checked = true"> 2. ACCESS is used to list the days of a day in a week. // This algorithm charges me an hour to query the data of all days of a day in a week. SELECT * FROM ctdate_by_query_dateWHERE dateandtime between (#2006-5-15 # + weekday (2006-5-15 )) -6) and #2006-5-15 # + Weekday (2006-5-15) 3. double-click the mouse to copy the text. Now, double-click the function ClipBoard (tdObj) {// IE Onlyvar holdtext = document. all ['holdtext']; holdtext. innerText = tdObj. innerText; Copied = holdtext.createtextrange(registry.copied.exe cCommand ("Copy"); alert ("text copied ");} </script> <form NAME = "form1" METHOD = "post" ACTION = ""> <ttextarea id = "holdtext" style = "display: none "ROWS =" 10 "> </ttextarea> </form>

Javascript automatically adapts to the size of the DIV and performs stretching so that the image is not repeatedly displayed.

I am too familiar with this. You can try it if you can.
Css:
. Div1 {width: 100px;} // you can set this parameter at will.
. Div1 img {width: 100% ;}
Html:
<Div class = "div1"> </div>

How does javascript set the image size?

Imge. width = 300; the value assignment cannot change the effect of the image displayed in the browser. I remember there is a way to change the attributes of an object with an id. For example, setbgcolor can be changed;
In addition, you can use css to control the class type of the img where the image is located. It is easier to use js to control css, so you do not need to use the service side;
In addition, you may have problems using firefox. You can check ie first.

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.