JS obtains all text controls in the page input control and appends style attributes.

Source: Internet
Author: User

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
}

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.