<div class="codetitle"> <span><a style="CURSOR: pointer" data="88253" class="copybut" id="copybut88253" onclick="doCopy('code88253')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code88253"> <br><br><br><br><br><br><title>判斷是否為數字及空格</title> <br><script type="text/javascript" src="jquery.min.js"></script> //這裡有無也無所謂<br><script type="text/javascript"><BR>function check_num() //建立函數<BR>{<BR> var Num=document.getElementById("num").value; //取得值(id=num)<BR> if(isNaN(Num) || Num=="" || Num.substring(0,0)==0) //注意substring函數用來判斷空格的<BR> { <BR> 非數字");<BR> return false;<BR> }else{<BR> alert("正確");<BR><body><BR>請輸入數字:<input type="text" id="num" name="num" value=""><BR><input type="submit" value="提交" o ~n~c~l~i~c~k~="check_num"> //這裡其實是onclick但是不讓寫<BR><BR><BR><BR></script> </div>