当使用input标签作为type="tel"触摸设备上的键盘时,输入框的类型对应.但是,我希望input隐藏标签中的值(与password类型一样).正常的行为是在用户输入时隐藏每个角色.
<input type="tel">
Run Code Online (Sandbox Code Playgroud)
input [type="tel"] {
-webkit-text-security: disc;
}
Run Code Online (Sandbox Code Playgroud)
此解决方案适用于大多数浏览器,但不适用于IE.
<input type="password" pattern="[0-9]*" inputmode="numeric">
Run Code Online (Sandbox Code Playgroud)
此解决方案无法按预期工作.
有没有办法完成我想要做的事情?
我已text-security:disc;按以下方式设置但它在firefox中不起作用.
text-security:disc;
-webkit-text-security:disc;
-mox-text-security:disc;
Run Code Online (Sandbox Code Playgroud)
我将这些属性设置为input[type='number']字段.有什么建议吗?
我有一个输入字段用于在网页中输入密码:
<input name="txtPassword" type="text" class="input2" id="txtPassword" value="Password" onfocus="txtOnFocus2('txtPassword','Password');" onblur="txtOnBlur2('txtPassword','Password');" />
Run Code Online (Sandbox Code Playgroud)
在初始状态下,用户应将"密码"作为初始值读取,当他开始输入密码时,该字段应更改为键入密码.此外,当他将其设置为空白或初始值时,该字段应将类型更改为"文本"并显示密码.
我编写了代码,让它可以在Firefox,Chrome和Safari上运行,并且不会在IE 8上将类型更改为密码.
这是我通过编辑现有功能代码制作的js代码:
function txtOnFocus2(elementId, defaultText)
{
if (document.getElementById(elementId).value == defaultText)
{
document.getElementById(elementId).value = "";
document.getElementById(elementId).type = "password";
}
}
function txtOnBlur2(elementId, defaultText)
{
var textValue = document.getElementById(elementId).value;
if (textValue == defaultText || textValue.length == 0)
{
document.getElementById(elementId).type = "text";
document.getElementById(elementId).value = defaultText;
}
}
Run Code Online (Sandbox Code Playgroud)
这在Firefox,Chrome和Safari中运行良好,但不会改变IE 8上的字段类型.