标签:out html 年龄 style 练习 get else inner highlight
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> function getAgeName(){ var age =document.getElementById(‘in‘).value; document.getElementById(‘bnt‘); if(!Number.parseInt(age)){ alert("年龄输出错误") } else if(age>=0&&age<=2){ document.getElementById(‘out‘).innerHTML="婴儿"; } else if( age>=3&&age<=5){ document.getElementById(‘out‘).innerHTML="儿童"; } else if(age>=6&&age<=12){ document.getElementById(‘out‘).innerHTML="少年"; } else if( age>=13&&age<=18){ document.getElementById(‘out‘).innerHTML="青少年"; } else if( age>=19&&age<=35){ document.getElementById(‘out‘).innerHTML="青壮年"; } else if( age>=36&&age<=45){ document.getElementById(‘out‘).innerHTML="中年"; } else if( age>=46){ document.getElementById(‘out‘).innerHTML="老年" } else { alert("年龄输出错误") } } </script> </head> <body> <input style="text" id ="in" value=" " /> <input type="button" onclick="getAgeName()" value="年龄所对应的状态" id="bnt"/> <div id="out"> </div> </body> </html>
标签:out html 年龄 style 练习 get else inner highlight
原文地址:http://www.cnblogs.com/wx1691790309/p/7406049.html