首页 > 代码库 > 模拟placeholder
模拟placeholder
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><body> <form id="form1" action=""> <input type="text" name="username" placeholder="请输入用户名"> <input type="password" name="password" placeholder="请输入密码"> <input type="text" name="email" placeholder="请输入邮箱"> </form> <script type="text/javascript"> (function(){ var elem = document.createElement(‘input‘); if(elem.placeholder !== undefined) return; var form = document.getElementById(‘form1‘), inputs = form.getElementsByTagName(‘input‘), i,input,value,type; for(i in inputs){ input = inputs[i]; type = ‘text‘; if(input.type !== ‘text‘ && input.type !== ‘password‘) continue; if(input.type === ‘password‘){ type = ‘password‘; input.type = ‘text‘; } value = input.getAttribute(‘placeholder‘); input.value = value; (function(value,type){ input.onfocus = function(){ if(this.value === value) this.value = ‘‘; if(type === ‘password‘) this.type = ‘password‘; } input.onblur = function(){ if(this.value === ‘‘) this.value = value; if(this.value === value && type === ‘password‘) this.type = ‘text‘; } })(value,type); } })(); </script></body></html>
模拟placeholder
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。