用代码来充实生活

梦想遥不可及
posts - 3, comments - 0, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

使用javascript转换首字母大写

Posted on 2012-08-12 12:49 mr.zhao 阅读(261) 评论(0)  编辑  收藏
 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 2 <html>
 3   <head>
 4     <title>MyHtml.html</title>
 5     
 6     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 7     <meta http-equiv="description" content="this is my page">
 8     <meta http-equiv="content-type" content="text/html; charset=gbk">
 9     <script type="text/javascript">
10         function zhuanHuan(){
11             var dc=document.getElementById("zimu").value;
12             var temp;
13             var temp1 = dc.charAt(0).toUpperCase();
14             for(var i=1;i<dc.length;i++){
15                 temp=dc.charAt(i);
16                 if(temp==" "&&i<dc.length-1){
17                     temp=" "+dc.charAt(i+1).toUpperCase();
18                     temp1=temp1+temp;
19                     i++;
20                 }
21                 else{
22                  temp1 = temp1 + temp;
23                 }
24             }
25             document.getElementById("zimuhou").value=temp1;
26         }
27     </script>
28   </head>
29   
30   <body>
31       <div>
32           <span>请输入单词:</span>
33           <input type="text" id="zimu"/>
34           <input type="button" value="转换首字母大写" onclick="zhuanHuan()"/>
35           <input type="text" id="zimuhou" />
36       </div>
37   </body>
38 </html>

只有注册用户登录后才能发表评论。


网站导航: