当前位置:编程学习 > JS >>

Javascript: String对象,将字符串“hAPPY,i'm a student,NOW”中的大写字母转换成小写字母,小写字母转换成大写字母

答案:写了一下,你试试看

<!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>
<script language="javascript">
function test(){
var temp = "hAPPY,i'm a student,NOW";
var temp1 = "";
for(var i=0; i<temp.length; i++){
var ch = temp.charAt(i);
var as = temp.charCodeAt(i);
if(65<=as&&as<=90){
temp1+=ch.toLowerCase();
}else if(97<=as&&as<=122){
temp1+=ch.toUpperCase();
}else{
temp1+=ch;
}
}
alert("前"+temp+"后"+temp1);
}
</script>
</head>

<body onload="test()">
</body>
</html>

<script language="javascript">
var str="hAPPY,i'm a stdent,NOW";
var temp_str="";
for (var i=0;i<str.length;i++){
var st=str.charAt(i);
if(st==st.toUpperCase())
temp_str =temp_str + st.toLowerCase();
else
temp_str += st.toUpperCase();
}
alert(temp_str);
</script>

上一个:把语句中javascript改C#能正常运行吗?Response.Write("<script>javascript:alert('添加成功');</script>");
下一个:运行以下 JavaScript 程序段后,变量m的值是______. var   x=4,y=5,m;   m=(x>y)?x:y;语言每句都什么意

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,