About JavaScript operations html

Source: Internet
Author: User
/*** Here we will briefly introduce how to use JavaScript to operate HTML elements. * We can use document. getelementbyid ("998"); get an element on a webpage */window. onload = Init; function Init () {var BTN = document. getelementbyid ("998"); // obtain a button var IMG = document. getelementbyid ("img1"); // obtain an IMG image. src = "JS/c.jpg"; // use Code Set the image SRC to be similar to  IMG. title = "image flip"; // use a string to assign an IMG value directly. classname = "hide"; alert (IMG. onclick); // you can view IMG information generated by HTML. onclick = onclick; // attribute and event are different settings. You need to assign an IMG function. onmouseover = onmouseover; IMG. onmouseout = onmouseout; BTN. innerhtml = "show image"; BTN. onclick = btn_click;} function onclick (event) {alert (1234);} function onmouseover (event) {This. src = "JS/B .jpg"; // remember to add this. Otherwise, SRC is the default attribute of a Windows Object and cannot start. Function onmouseout (event) {This. src = "JS/c.jpg"; // The attribute value must be explicitly specified, just like the this pointer in Java. Attributes depend on objects. Similarly, this method also depends on the object.} function btn_click () {// The parameter cannot be passed for the event method. It looks like. We can use this to call the current object. If ("show image" = This. innerhtml) {var IMG = document. getelementbyid ("img1"); // if you want to use other elements, we can obtain IMG. classname = "show"; this. innerhtml = "Hide image";} else if ("Hide image" = This. innerhtml) {var IMG = document. getelementbyid ("img1"); IMG. classname = "hide"; this. innerhtml = "show image ";}}

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.