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.