码迷,mamicode.com
首页 > 编程语言 > 详细

javascript "非法值"检验.

时间:2014-10-12 21:55:18      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   java   sp   div   on   

 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 "非法值"检验.

标签:style   blog   color   io   ar   java   sp   div   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!