2014-09-13 20 views
4

我按照以下方式設置了text-security:disc;,但它在firefox中不起作用。-webkit-text-security兼容性

text-security:disc; 
-webkit-text-security:disc; 
-mox-text-security:disc; 

我將這些屬性設置爲input[type='number']字段。任何建議?

+0

您正在使用什麼版本的?檢查瀏覽器支持http://www.browsersupport.net/CSS/-webkit-text-security – Richa 2014-09-13 11:26:28

+0

是否有其他可用的替代方法可以在任何地方使用? – sagarpatidar 2014-09-13 11:27:48

+0

是的,你可以檢查這個http://stackoverflow.com/questions/13822548/degrading-webkit-text-security – Richa 2014-09-13 11:28:17

回答

4
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"); 
    } 
} 

CSS

input { 
    text-security: disc; 
    -webkit-text-security: disc; 
    -moz-text-security: disc; 
} 
+0

這對我有效。我用jQuery雖然 – Paolo 2016-03-18 07:59:14

+0

'x.setAttribute(「type」,「password」);'打破OP的'input [type ='number']'設置? – 2017-10-23 20:56:54

+0

它不會觸發手機號碼簿 – 3gwebtrain 2017-11-10 02:14:18