这是非常快捷和肮脏的,但是可以。
<html><head> <style> input{ -webkit-text-security:square; text-security:square; }</style> <script> window.onload = function(){ init(); } function init(){ var x = document.getElementsByTagName("input")[0]; var style = window.getComputedStyle(x); console.log(style); if(style.webkitTextSecurity){ //do nothing }else{ x.setAttribute("type","password"); } } </script></head><body> <div id="di"> <input/> </div></body>我在chrome和firefox上测试过,我在linux上,所以我不能在IE中测试。
Jsfiddle在这里。



