将配置数据从代码中分离出来

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 5     <title>Document</title>
 6 </head>
 7 <body>
 8     <script>
 9     var config = {
10         "MSG_INVALID_VALUE": "Invalid value",
11         "URL_INVALID": "/errors/invalid.php",
12         "CSS_SELECTED": "selected"
13     };
14 
15     function validate(value) {
16         if (!value) {
17             alert(config.MSG_INVALID_VALUE);
18             location.href = config.URL_INVALID;
19         }
20     }
21 
22     function toggleSelected(element) {
23         if (hasClass(element, config.CSS_SELECTED)) {
24             removeClass(element, config.CSS_SELECTED);
25         } else {
26             addClass(element, config.CSS_SELECTED);
27         }
28     }
29     </script>
30 </body>
31 </html>

 

posted @ 2013-04-16 15:07  小猩猩君  阅读(385)  评论(0编辑  收藏  举报