<!DOCTYPE html>
<html>
<head>
<title>2.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</script>sdfadsdf
<script >
function ischeckNum()
{
var num = document.getElementById('isnum').value;//在此處下修改id
if( num )
{
if( !isNaN( num ) )
{
if(num.length>11){
$("#isnum").val("");//清空
alert("當前輸入的手機號碼大於11位,請輸入11位的手機號碼");
}else if(num.length<11 && num.length>0){
$("#isnum").val("");
alert("當前輸入的手機號碼小於11位,請輸入11位的手機號碼!");
}
return false;
}
else
{
alert('你輸入的數據不是數字');
myfm.isnum.select();
return false;
}
}
else
{
alert('需輸入內容');
myfm.isnum.focus();
}
}
</script>
</head>
<body>
<form name="myfm" method="post" action="">
<label>
<input type="text" name="isnum" id="isnum">
</label>
<label>
<input type="button" name="Submit" value="檢測是否爲數字" onClick="ischeckNum();">
</label>
</form>
</body>
</html>