我这样写if...else的格式有错吗?为什么最后一步就是执行不了?

为什么代码前面都可以执行,最后一步else怎么改都执行不了,到底是哪里错了。

function checkName(){

var checkname=document.getElementById("name").value;   //读取用户输入信息

if((checkname=="") || (checkname ==null)){        //判断用户名是否为空

var name="请输入用户名!";

yonghuming.innerHTML=name;

form1.name.focus();

return;

}

else if(checkname.length<2){

    name="请输入正确姓名!"

    yonghuming.innerHTML=name;

    form1.name.focus();

    return;

}else if(checkname.length>=2){

    for(var i=0;i<checkname.length;i++){

    if(checkname.charCodeAt(i)<=225){               name="请输入姓名的正确格式!";  

    yonghuming.innerHTML=name; 

    form1.name.focus();

    return;

       }

   }

}***else{       

       name="✔";   

       yonghuming.innerHTML=name; 

       return;    

     }***

}    

    


阿波罗的战车
浏览 580回答 1
1回答

Helenr

你的最后一个else应该写在if(checkname.charCodeAt(i)<=225)这个判断的后面吧:var checkname = document.getElementById("name").value; //读取用户输入信息&nbsp; &nbsp; &nbsp; &nbsp; if((checkname == "") || (checkname == null)) { //判断用户名是否为空&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var name = "请输入用户名!";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yonghuming.innerHTML = name;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form1.name.focus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; } else if(checkname.length < 2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name = "请输入正确姓名!"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yonghuming.innerHTML = name;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form1.name.focus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; } else if(checkname.length >= 2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(var i = 0; i < checkname.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(checkname.charCodeAt(i) <= 225) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name = "请输入姓名的正确格式!";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yonghuming.innerHTML = name;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form1.name.focus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name = "✔";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yonghuming.innerHTML = name;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }像你写在外面的很明显的是逻辑错误嘛
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript