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)