<iframe id="iframeu1788635_0" src="http://pos.baidu.com/oclm?rdid=1788635&dc=2&di=u1788635&dri=0&dis=0&dai=2&ps=236x1186&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1463411112505&ti=html%20input%E5%AF%86%E7%A0%81%E6%98%BE%E7%A4%BA%E4%B8%BA%E2%80%9C*%E2%80%9D%20%7C%20%E5%AD%A6%E6%AD%A5%E5%9B%AD&ari=1&dbv=2&drs=1&pcs=1920x944&pss=1920x256&cfv=0&cpl=42&chi=1&cce=true&cec=UTF-8&tlm=1463411112&ltu=http%3A%2F%2Fwww.xuebuyuan.com%2F1346201.html&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DVs3tEP5iZQfx6Cb7pwpMufYiLuUJCXSKNX77tSLDdRtZ4XKJ651fNsqaYtnxGdfW%26wd%3D%26eqid%3De70e1f4e0005586c000000055739e1a2&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=true&cmi=68&col=zh-CN&cdo=-1&tcn=1463411113&qn=bea78df439f68afc&tt=1463411112477.113.209.250" width="336" height="280" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="margin: 0px; padding: 0px; border: 0px; vertical-align: bottom; background: transparent;"></iframe>
1. 功能需求:HTML中,在input password输入框中输入字符将默认显示为“实体圆点”,但这里要求将实体圆点字符替换成“*”号显示。
2. 局限:鼠标光标非IE浏览器不一定显示,选择多个字符时未有视觉上的区分,功能没有影响;不支持中文输入。
3. 实现:通过两个input框实现,设置字符字体为等宽字体;其中真正的密码输入框设置为透明且遮盖住另一输入框,将非密码输入框的字符依密码字符串的多少显示“*”字符的个数。
附上测试文件如下:
<!DOCTYPE html><html encoding="utf-8"><head> <style> *{margin:0;padding:0} input{font:14px Monospace;height:20px;width:160px;} label{display:inline-block;width:100px;height:20px;} #pass{position:absolute;left:100px;top:0;opacity:0;filter:alpha(opacity=0);z-index:2;} form{position:relative;} #hint_pass{position:absolute;left:100px;} </style></head><body> <form> <label>Password:</label> <input type="text" id="hint_pass" maxlength="20" tabindex="-1" /> <input type="text" id="pass" name="pass" maxlength="20" /> </form> <script> var pass=document.getElementById('pass'); var hint_pass=document.getElementById('hint_pass'); pass.pass.function(){hint_pass.value=pass.value.replace(/./g,'*');};</script> </body></html>