日期:2014-05-17 浏览次数:20670 次
<script type="text/javascript" language="javascript"> //<!-- 1 只允许输入数字 --> $(document).ready(function() { $('.error').hide(); $('.submit').click(function(event) { var data=$('.infobox').val(); var len=data.length; var c=0; for(var i=0; i<len; i++) { c=data.charAt(i).charCodeAt(0); if(c==45 && i==0) //允许负值; { continue; } if(c<48 || c>57) { $('.error').show(); event.preventDefatult(); break; } else { $('.error').hide(); } } }); }); </script>
<form id='signup' method="post" action=""> <div> <span class="label"> Enter Age </span> <input type="text" class="infobox" /> <span class="error">Only numericals allowed</span> </div> <input class="submit" type="submit" value="Submit" /> </form>