为什么jQuery不将#password_input的type属性更改为password?
<html>
<head>
<title></title>
<style type="text/css">
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#password_input").attr('type','password');
});
</script>
</head>
<body>
<div id="loginBox">
<form>
<input type="text" id="username_input" name="username" /><br />
<input type="text" id="password_input" name="password" />
</form>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 25
是的你可以.
尝试这是它的作品
<input type="text" class="pwd">
$('.pwd').click(function(){
$(this).get(0).type='password';
});
Run Code Online (Sandbox Code Playgroud)
这是一种安全措施,大多数主流浏览器都采用这种措施来减轻屏幕阅读和密码被盗(从另一个方面来说,更重要的是从那里password开始text).
我无法从你的代码中看出你正在尝试做什么,但这是我的猜测:你想要一个带有单词的文本框Password作为提示,当它获得焦点时,用户输入他们的密码作为密码字段.要实现此目的,您可以使用两个元素:an <input type="text">和an <input type="password">,后者最初隐藏.当用户专注于文本框时,只需隐藏它,显示密码字段,然后设置焦点.它可能会在它们之间来回切换.
现在,这在现代浏览器中更容易实现.只需使用这样的东西(这里是一个jsFiddle):
<input type="password" placeholder="Password" />
Run Code Online (Sandbox Code Playgroud)
您始终可以使用纯 js,例如:
document.getElementsByName("login_pass")[0].type="text";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40217 次 |
| 最近记录: |