<p align="left">有两个变量 a 和 b <br>如果a=1,3,5,7,9 则b="奇数" <br>如果a=2,4,6,8 则b="偶数" <br>如果a="0" 则b="零" <br></p> <div class="htmlarea"> <textarea id="runcode62653"> <script language="JavaScript" type="text/javascript"> <!-- function chk(num){ return num?num%2?"奇数":"偶数":"0" } function show(num){ if(num=="") {alert("没有填写数字!");return false;} if(isNaN(num)) {alert("非数字!");return false;} if(num>9){alert("大于9被强行改为1");alert(chk(1));}else if(num<0){alert("小于0被强行改为0");alert(chk(0));}else if(num==0){alert(chk(0));}else{alert(chk(num))} } //--> </script> <form name="abc"> <input name="num" id="num" type="text" value=""> <input name="chk" id="chk" type="button" value="检查" onclick="show(this.form.num.value)"> </form> </textarea><br><input onclick="runEx('runcode62653')" type="button" value="运行代码"> <input onclick="doCopy('runcode62653')" type="button" value="复制代码"> <input onclick="doSave(runcode62653)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>