For example, jquery is used to obtain all the text controls in the page input control and add styles during page loading.
The width attribute of the text control used on the previously written page is too small to be changed. modifying all the text attributes on the page will cause trouble to change the width of each control, so I want to find the text to be modified during page loading and add attributes.
First, write a css style.:
Copy codeThe Code is as follows:
. Wid
{
Width: 205px;
}
The code written in page loading is as follows::
$ ("Input [type = text]"). addClass ("wid"); // obtain all the controls of type = text in the input control and add the style to the text box. This completes.
Javascript gets the page control and append the style:
Copy codeThe Code is as follows:
// Add a style to the select drop-down box
Var g = document. getElementsByTagName ("select"); // set the variable to receive the select control found
For (I = 0; I <g. length; I ++) // traverses the cyclic value assignment.
{
Document. getElementById (g [I]. id). style. width = "210px"; // additional style
}