Simple Method for setting css styles with cssText in js, jscsstextcss styles
If a tag with the id "no" is displayed on the webpage, tell is used as the div label;
To set the css style of this div in js, it is common:
Var obj = document. getElementByIdx_x_x ('no'); obj. style. width = '400px '; obj. style. height = '300px ';
If you want to set a bunch of css styles, it is too troublesome to put,
Generally, css is used to add className or change className to achieve the desired effect. But if you create an element, do you still want to make it easier? You have to find another solution ~
So we wrote one function after another. The classic two are:
Var obj = document. getElementByIdx_x_x ('no'); function setStyle (obj, css) {for (var attr in obj) {obj. style [attr] = css [attr] ;}} setStyle (obj, {width: "400px", height: "300px "});
Of course, there is more simple, cssText:
Var obj = document.getelementbyidx_x_x('no'{}obj.style.css Text = "width: 400px; height: 300px ;";
Of course, this method is very easy for the create element to initialize the css style.
The above is all about the simple method for setting css styles with cssText in js provided by xiaobian. I hope it will be helpful to you and support more help ~