<script type="text/javascript"> function checkRoleName(){ var userName=document.getElementById("roleName").value; if(userName.replace(/s/g,'')==''){ alert("请输入角色名称"); document.getElementById("roleName").focus(); return false; }else{ return true; } } </script>
if(userName.replace(/s/g,'')=='') 用正则表达式,替换空格