快捷导航

判断js input的值是否正确,看代码

window.onload=function(){                phonenum=document.getElementById("phonenum1").value;                //varvphonenum=phonenum;                //alert(vphonenum);                //returnfalse;                but=document.getElementById("but");                but.onclick=(function(){                        if(phonenum===""){                                alert("手机号码不能为空,请重新输入");                                returnfalse;                        }else{                                alert(phonenum);                        }                });                        }        这样写对吗?表单有值也会alert,没有值也会弹出alert

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2

把phonenum=document.getElementById("phonenum1").value;写到onclick里面去
回复

使用道具 举报

phonenum=document.getElementById("phonenum1").value;页面一加载就获取文本框的值肯定是空,这句话应该放到onclick事件里面去,点击的时候再去取值才对
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP