摘要:angularJS+Jquery讓Input type='TEXT' 只能輸入數字
使用線上編輯器:http://jsbin.com/UyETIlA/1/edit
<!DOCTYPE html>
<html ng-app>
<head>
<title>Welcome to JS Bin</title>
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<SCRIPT LANGUAGE="JavaScript">
function ValidateNumber(e, pnumber)
{
if (!/^\d+$/.test(pnumber))
{
$(e).val(/^\d+/.exec($(e).val()));
}
return false;
}
</SCRIPT>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js">
</script>
</head>
</head>
<body>
<div class="wrapper">
<input type="text" id="S" name="S" ng-model="input" onkeyup="return ValidateNumber($(this),value)" />
{{input}}
</div>
</body>
</html>
REF.. http://demo.tc/Post/617