<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function checkletter(){
var letter="ABCDEFGHIJKLMNOPQRSTUVWXYZ" // 24个英文字母
var text2=document.form1.text2.value; // 获取text2的值
for(i=0;i<=text2.length;i++){
var charletter=text2.charAt(i); // 将text2的字符一个一个的返回
charletter=chartletter.toUpperCase(); //将返回的值变为大写
if(letter.indexOf(charletter)==-1){ //判断没有大写字母
alert("输入的类型必须为英文");
return false; //还有这个return 返回的是什么东西
}
}
}
function checktext2(){
document.form1.text2.value="";
}
</script><style type="text/css"></style>
</head>
<body>
<form name="form1">
<p>检查是否含有英文字母:
<input type="text" name="text2" value="请输入字母" onclick="checktext2()"/>
<input type="button" name="button2" value="检查是否含有英文字母" onclick="checkletter()" />
</p>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function checkletter(){
var letter="ABCDEFGHIJKLMNOPQRSTUVWXYZ" // 24个英文字母
var text2=document.form1.text2.value; // 获取text2的值
for(i=0;i<=text2.length;i++){
var charletter=text2.charAt(i); // 将text2的字符一个一个的返回
charletter=chartletter.toUpperCase(); //将返回的值变为大写
if(letter.indexOf(charletter)==-1){ //判断没有大写字母
alert("输入的类型必须为英文");
return false; //还有这个return 返回的是什么东西
}
}
}
function checktext2(){
document.form1.text2.value="";
}
</script><style type="text/css"></style>
</head>
<body>
<form name="form1">
<p>检查是否含有英文字母:
<input type="text" name="text2" value="请输入字母" onclick="checktext2()"/>
<input type="button" name="button2" value="检查是否含有英文字母" onclick="checkletter()" />
</p>
</form>
</body>
</html>
charletter=chartletter.toUpperCase(); //将返回的值变为大写上面这行的变量名打错了chartletter 多了一个t