- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>无标题文档</title>
- </head>
- <body>
- <p>
- <input type="text" id="da" />
- <input type="button" value="换成大写" οnclick="da()" />
- <input type="text" id="da1" />
- <p>
- <input type="text" id="xiao" />
- <input type="button" value="换成小写" οnclick="xiao()" />
- <input type="text" id="xiao1" />
- <p>
- <input type="text" id="huoqu1" />
- <input type="text" id="huoqu2" size="5"/>确认截取长度
- <input type="button" value="获取字符串" οnclick="jiequ()"/>
- <input type="text" id="huoqu3" />
- <p>
- <input type="text" id="chazhao1" />
- <input type="button" value="查找@字符" οnclick="cha()"/>
- <input type="text" id="chaozhao2" />
- </body>
- <script language="javascript">
- function da()
- {
- var a = document.getElementById("da").value;
- document.getElementById("da1").value = a.toUpperCase();
- }
- function xiao()
- {
- var a = document.getElementById("xiao").value;
- document.getElementById("xiao1").value = a.toLowerCase();
- }
- function jiequ()
- {
- var a=new String (document.getElementById("huoqu1").value);
- document.getElementById("huoqu3").value=a.substring(0,parseInt(document.getElementById("huoqu2").value));
- }
- function cha()
- {
- var a=new String (document.getElementById("chazhao1").value);
- document.getElementById("chaozhao2").value=a.indexOf("@",0)+1;
- }
- </script>
- </html>
课后作业(五)String对象的常用属性和方法
最新推荐文章于 2022-10-25 21:21:46 发布