web前端|js教程
JavaScript,监听,文本框,回车事件,过滤空格
web前端-js教程
本文实例讲述了JavaScript监听文本框回车事件并过滤文本框空格的方法。分享给大家供大家参考。具体如下:
酒店预订网站php源码,vscode双机同步编辑,ubuntu 屏幕扩展,tomcat中添加编码,爬虫投票,php用户行为,黄陂seo优化分析,网页模板网站cms,帝国cms动漫模板下载lzw
var username = null;var password = null;//获取文本框 onload = function(){ username = document.getElementById("txtUserName"); password = document.getElementById("txtPassWord"); }//清空文本框function clearTxt(){ username.value = ""; password.value = ""; username.focus(); // document.getElementById( xtUserName).value=""; // document.getElementById( xtPassWord).value=""; // document.getElementById( xtUserName).focus(); } //确定function chkTxt(){ //删除前后空格 username.value = username.value.replace(/(^\s*)|(\s*$)/g,""); password.value = password.value.replace(/(^\s*)|(\s*$)/g,""); //判空 if(username.value.length == 0) { alert("请输入用户名!"); username.focus(); } else if(password.value.length == 0) { alert("请输入密码!"); password.focus(); } else document.getElementById("btnLogin").click();}//回车监听function onkey(){ if (window.event.keyCode==13) {// document.all["btnLogin"].focus();// if(document.activeElement.id = "aReset")//判断当前焦点所在的控件的id是aReset// {//document.getElementById("aReset").focus();// } document.getElementById("aLogin").focus(); return false; }}
css代码:
备忘录 源码,vscode 未跟踪怎么回事,ubuntu创建项目,tomcat8 mvn,pycharm 开发爬虫,php字符串求和,河南网络推广郑州seo优化收费,网站后台编辑器源码lzw
#btnLogin { width: 0px; height: 0px; border-style: none; background-color: White; }
html代码:
帝国cms伪静态源码,vscode运行打不开浏览器,ubuntu网卡设定,Tomcat怎么改版本,caiji爬虫软件,php对接java接口,温江区seo网络推广引流lzw
//把回车监听加入body
确定重置