简体   繁体   English

HTML和Javascript:使用自定义的文本输入进行密码输入

[英]HTML & Javascript: Using a customized Text Input for Password input

I want to re-invent the password input in HTML. 我想重新发明HTML中输入的密码。

Okay, here is the work I'd done: 好的,这是我已经完成的工作:

http://www.symplik.com/password.html (It just a plain html code, nothing really fancy :>) http://www.symplik.com/password.html (这只是一个纯HTML代码,没有什么特别花哨的地方:>)

The "password" is indeed a text input, and I used the onkeyup event to rewrite the input to masking characters. “密码”确实是文本输入,并且我使用onkeyup事件将输入重写为掩码字符。

There're two problems: (1) backspace or delete cannot be detected (2) if I type very fast, some characters cannot be captured promptly. 有两个问题:(1)无法检测到退格或删除(2)如果我快速键入,某些字符将无法立即捕获。

For problem (1). 对于问题(1)。 it is partially solved by checking the length of text in the password field and the stored password. 通过检查密码字段中的文本长度和存储的密码可以部分解决此问题。 Not a very elegant solution anyway. 无论如何,这不是一个非常优雅的解决方案。

For problem (2), I'd tried to insert some time delay function in between but still fail. 对于问题(2),我试图在两者之间插入一些延时功能,但仍然失败。 I'd make the field readOnly after every keyUp but it still behaves the same. 我会在每次keyUp之后将字段设置为readOnly,但是它的行为仍然相同。

Why not use 为什么不使用

<input type='password'>

It masks the input for you. 它为您屏蔽了输入。 No need for javascript . 不需要javascript

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM