A small bug in the MS Atlas (Ajax Control Toolkit) Sample project

Source: Internet
Author: User
The Ajax Control Toolkit (Code: Atlas) of MS is recently studied. The alwaysvisiblecontrol demonstration example has a small error.

Complete example and source code:
Http://www.codeplex.com/Release/ProjectReleases.aspx? Projectname = atlascontroltoolkit

The/samplewebsite/alwaysvisiblecontrol. ASPX page contains an incorrect updatetime function.

Function updatetime ()
{
VaR label = Document. getelementbyid ('ctl00 _ contentplaceholder1_currenttime ');
If (Label ){
VaR time = (new date (). tolocaletimestring ();
Time = time. match (/^ (\ s * \ D {1, 2} \ s * \: \ s * \ D {1, 2} \ s *\: \ s * \ D {1, 2} \ s * [A-Za-Z] {2 }). * $/) [1];
Label. innerhtml = time;
}
}

If you select a Chinese operating system or a regional system, the system will not work properly. The problem lies in the regular expression matching. Because the US time format is 10:50:27 am, you can use (/^ (\ s * \ D {1, 2} \ s *\: \ s * \ D {1, 2} \ s * \: \ s * \ D {1, 2} \ s * [A-Za-Z] {2 }). * $/). However, the time format in China is 11:21:15 without AM/PM. Therefore, the matching result is null, leading to JS errors, at the same time, let's review a small piece of knowledge. For Regular Expression matching, the 0 element of the array contains the entire match, and the 1st to N element contains any child match that has appeared in the match. Finally, modify the JS function as follows:

Function updatetime ()
{
VaR label = Document. getelementbyid ('ctl00 _ contentplaceholder1_currenttime ');
If (Label ){
VaR time = (new date (). tostring ();
Time = time. match (/(\ D {1, 2} \ s * \: \ s * \ D {1, 2} \ s * \: \ s * \ D {1, 2 }). */) [1];
Label. innerhtml = time;
}
}

In this way, it is fully compatible with all regions.
(Full text)

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.