1 <script type="text/javascript">
2 function getCoord() {
3 var x = document.getElementById('xTxt').value;
4 if(isEmptyOrSpaces(x)) {
5 alert('请输入x坐标');
6 return;
7 }
8 //值必须为数字.
9 if(isNaN(x)) {
10 alert('x值非法');
11 return;
12 }
13
14 var y = document.getElementById('yTxt').value;
15 if(isEmptyOrSpaces(y)) {
16 alert('请输入y坐标');
17 return;
18 }
19 if(isNaN(y)) {
20 alert('y值非法');
21 return;
22 }
23 }
24
25 //测试文本框值不能为空.
26 function isEmptyOrSpaces(val) {
27 return val === null || val.match(/^ *$/) !== null; //"!=="是严格的"不等"
28 }
29 </script>