设置密码输入的默认值以便读取 [英] Set default value of a password input so it can be read

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

问题描述

我想在用户输入密码之前设置一个密码字段,用于输入密码(所以他们知道字段是什么)。



我会而只是使用Javascript,单独导入jQuery看起来很浪费,但我不知道如何去做。这些图像很清楚地解释:

它看起来像: b



我想要什么看起来像:





这只是一个非常简单的网站和最基本的登录信息(没有验证等)

任何想法?

 < input id =usernamename =usernameclass =input_texttype =text value =用户名/> 
< input id =passwordname =passwordclass =input_texttype =passwordvalue =Password/>


解决方案

更改您的密码输入为简单输入类型 text 。然后,在焦点事件上使用JavaScript(或JQuery),将其更改为输入类型 password



是一个没有经过测试的普通JavaScript样例(没有JQUERY):

 < html> 
< head>
< script type =text / javascript>
函数makeItPassword()
{
document.getElementById(passcontainer)
.innerHTML =< input id = \password \name = \ password \type = \password \/>;
document.getElementById(password)。focus();
}
< / script>
< / head>
< body>
< form>
< span id =passcontainer>
< input onfocus =return makeItPassword()name =passwordtype =textvalue =输入密码/>
< / span>
< / form>
< / body>
< / html>


I want to have a password field which says "Password" in it before a user enters their password (so they know what the field is)

I'd rather just use Javascript, importing jQuery for this alone seems wasteful, but I have no idea how to. The images explain quite clearly:

What it looks like:

What I want it to look like:

It's only a very simple website and the most basic of logins (has no validation etc)

Any ideas?

<input id="username" name="username" class="input_text" type="text" value="Username"  />
<input id="password" name="password" class="input_text" type="password" value="Password" />                 

解决方案

Change your password input to be a simple input type text. Then, with JavaScript (or JQuery) on focus event, change it to be a input type password.

Here is a little untested sample with plain JavaScript (no JQUERY):

<html>
<head>
   <script type="text/javascript">
      function makeItPassword()
      {
         document.getElementById("passcontainer")
            .innerHTML = "<input id=\"password\" name=\"password\" type=\"password\"/>";
         document.getElementById("password").focus();
      }
   </script>
</head>
<body>
   <form>
      <span id="passcontainer">
         <input onfocus="return makeItPassword()" name="password" type="text" value="Type Password" />
      </span>
   </form>
</body>
</html>

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

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