实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> </title> <style type="text/css"> .box{width:310px;height:150px;border:1px solid red;margin:100px auto;padding:10px;} h2{width:250px;height:20px;display: block;line-height: 20px;margin:0 auto;text-align:center;} </style> <script type="text/javascript"> var number,text,jieguo; window.onload=function(){ text=document.getElementById('text'); jieguo=document.getElementById('jieguo'); } function jisuan(){ var a=Number(text.value); if(typeof(a)=="number"){ if(!isNaN(a)){ if(a>=90 ){ jieguo.innerHTML=a+"优秀"; }else if(a>=80){ jieguo.innerHTML=a+"良好"; }else if(a>=79){ jieguo.innerHTML=a+"一般"; }else if(a>=60){ jieguo.innerHMTL=a+"及格"; }else{ jieguo.innerHTML=a+"要努力呀"; } }else{ jieguo.innerHTML="你输入的不是数字,请重新输入"; } } } </script> </head> <body> <div class="box"> <h2>判断成绩</h2><br> <span>请输入成绩:</span> <input id="text" type="text" value=""><input type="button" onclick="jisuan();" value="判断"><br> <span id="jieguo"></span> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例