小项目----4
作者:互联网
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> 注册:<br/> <form name="form" meethod="post" action="#"> 姓名:<input name="username" type="text">* 年龄:<input name="age" type="text">* <select name="sel_city"> <option value="0">--请选择城市--</option> <option value="北京">北京</option> <option value="上海">上海</option> <option value="广州">广州</option> </select> <input name="city" size="12" readonly="readonly" type="text">* <input type="submit" name="btn" id="btn" value="提交"> </form> <script> form.username.onmouseover = function(){ this.focus(); this.select(); } form.age.onmouseover = function(){ this.focus(); this.select(); } form.age.onkeydown = function(ev){ oEven = ev || even; if(oEven.keyCode<48 || oEven.keyCode>57){ return false; } } form.sel_city.onchange = function(){ if(this.value==0){ alert('请选择一个城市'); }else{ form.city.value = form.sel_city.value; } } form.onsubmit = function(){ if(form.username.value==''){ alert('姓名为填写,无法提交'); form.username.focus(); return false; }else if(form.age.value==''){ alert('年龄未填写,不能提交'); form.age.focus(); return false; }else if(form.city.value=='' || form.city.value=='请选择城市'){ alert('城市未提交,不能提交'); form.sel_city.focus(); return false; } } form.city.onmouseover = function(){ if(this.value==''){ this.value = '请选择城市'; } } </script> </body> </html>
标签:function,city,false,form,项目,focus,value,---- 来源: https://www.cnblogs.com/wgqy/p/16382416.html