首页 > 编程语言 > 详细

javascript "非法值"检验.

时间:2014-10-12 21:19:49      阅读:294      评论:0      收藏:0      [点我收藏+]
 1 function getCoord() {
 2             var x = document.getElementById(‘xTxt‘).value;
 3             if(isEmptyOrSpaces(x)) {
 4                 alert(‘请输入x坐标‘);
 5                 return;    
 6             }
 7             //值必须为数字.
 8             if(isNaN(x)) {
 9                 alert(‘x值非法‘);
10                 return;    
11             }
12             
13             var y = document.getElementById(‘yTxt‘).value;
14             if(isEmptyOrSpaces(y)) {
15                 alert(‘请输入y坐标‘);
16                 return;    
17             }
18             if(isNaN(y)) {
19                 alert(‘y值非法‘);
20                 return;    
21             }
22         }
23         
24         //测试文本框值不能为空.
25         function isEmptyOrSpaces(val) {
26             return val == null || val.match(/^ *$/) !== null;
27         }

 

javascript "非法值"检验.

原文:http://www.cnblogs.com/listened/p/4021027.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!