How to obtain the Javascript dom object ..

Source: Internet
Author: User
Today, we need to use a select change event to obtain the months with configuration using ajax (just as there is a record ), and the configured month is returned in the form of a string, such as: 3, 4, 5, 6, and 7. The Code is as follows // change event of the year selector... SyntaxHighlighter. all (

Today, we need to use a select change event to obtain the months with configuration using ajax (just as there is a record ), the configured month is passed as a string, for example:

Returns in the form of 3, 4, 5, 6, and 7.

The Code is as follows:

 

// Change event of the year selector $ ("# year "). change (function () {for (var I = 1; I <= 12; I ++) {document. getElementById ("month" + I ). style. background = "# c0c0c0";} $. ajax ({type: "POST", data: {"yearSelect": $ (this ). val ()}, dataType: "TEXT", url: "<% = path %>/rewardList. do? Method = changeMonth ", success: function (result) {if (result. trim ()! = "") {Var monthed = result. split (","); for (var I = 0; I
 
  


There is no problem in the above Code, but if this sentence is changed to Javascript in dom mode, the dom object will never be obtained in the last month, and this dom object exists, the data is also completely normal.

That is, the following error occurs: document. getElementById (id). style. background = "orange ";

The preceding operations are normal.

 

Example:

When the data is 1, 2, 3, 5, 6

Month1, mon2, month3, and month5 can change the color normally. The last one, no matter what the number is, is always incorrect. The Firefox JS error console prompts:

Document. getElement (...) is null. That is to say, he does not get this object. JQUERY can be used.

But he actually exists .. So it's hard to understand ..

 

 

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.