Javascript Control div property dynamic change instance analysis _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how Javascript controls the dynamic changes of div attributes, and analyzes in detail the skills of JavaScript responding to mouse events to dynamically operate page element attributes in the form of examples, which has some reference value, for more information about how to control the dynamic changes of p attributes in Javascript, see the example in this article. Share it with you for your reference. The details are as follows:

Here, JS is used to control the change of p attributes, and the geometric size of the other Div changes, such as widening, increasing, changing the color, hiding the Div, and resetting all attributes to the default value. Although in this example, the changes to these attribute values can be easily implemented, this attribute or method is often used in JavaScript web page front-end design, so it is worth your attention.

The running effect is as follows:

The Online Demo address is as follows:

Http://demo.jb51.net/js/2015/js-cha-p-opt-demo/

The Code is as follows:

Javascript controls p attribute changesScript var changeStyle = function (elem, attr, value) {elem. style [attr] = value}; window. onload = function () {var oBtn = document. getElementsByTagName ("input"); var oDiv = document. getElementById ("p1"); var oAtt = ["width", "height", "background", "display", "display"]; var oVal = ["200px ", "200px", "red", "none", "block"]; for (var I = 0; I <oBtn. length; I ++) {oBtn [I]. index = I; oBtn [I]. onclick = function () {this. index = oBtn. length-1 & (oDiv.style.css Text = ""); changeStyle (oDiv, oAtt [this. index], oVal [this. index]) }}; script

I hope this article will help you design JavaScript programs.

Related Article

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.