密码字段默认值 [英] Password field default value

查看:103
本文介绍了密码字段默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能使用HTML密码输入并设置一个文本默认值,因为密码输入会将字符转换为点或星号,因此这些默认值将是可读的?我可以用Javascript来做到这一点吗?

直到有人点击它,这时它会变成空白,并且在那里键入的任何东西都会变成*的?好的,你想要的是这样的:



在头:

 < ; script type =text / javascript> 
function changefield(){
document.getElementById(passwordbox)。innerHTML =< input id = \password-field \type = \password \name = \password-field \title = \Password \/>;
document.getElementById(password-field)。focus();
}
< / script>

在正文中:

 < div id =passwordbox> 
< input id =password-fieldtype =textname =password-fieldtitle =Passwordonfocus =changefield(); value =password/>
< / div>


How can I both use the HTML password input and set a text default value that will be readable since the password input will turn the characters into dots or stars? Can I do this with Javascript?

解决方案

So if I understand correctly, you want it to read "password" or whatever in regular letters until someone clicks on it, at which point it will turn blank, and anything typed in there will become *'s? Ok what you want is this:

in head:

<script type="text/javascript">
    function changefield(){
        document.getElementById("passwordbox").innerHTML = "<input id=\"password-field\" type=\"password\" name=\"password-field\" title=\"Password\" />";
        document.getElementById("password-field").focus();
    }
</script>

in the body:

<div id="passwordbox">
<input id="password-field" type="text" name="password-field" title="Password" onfocus="changefield();" value="password" />
</div>

这篇关于密码字段默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆