日期:2014-05-16 浏览次数:20347 次
function CheckData(value) { var txt = value; if(txt.search("^-?\d+(\.\d+)?$")!=0){ return false;} txt = value; if(txt.search("^-?\d+$")!=0){ return false; } return true; }
var str = '123'; alert( !isNaN(str) )
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>无标题文档</title>
</head>
<body>
<div id="test"></div>
<input type="text" id="num" />
<input type="button" id="but" value="检索" />
<script src="../jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#but").click(function(){
var getNum = $("#num").val();
var reg = /\d/;
$("#test").text(getNum);
if(!reg.test(getNum)){
alert("没有数字");
}
else{
alert("包含数字");
}
})
})
</script>
</body>
</html>