- <input name="password" type="text" id="showPwd" tabindex="2" class="input" value="密码" />
<input name="password" type="text" id="showPwd" tabindex="2" class="input" value="密码" />
- $("#showPwd").focus(function(){
- $(this).attr('type','password');
- });
$("#showPwd").focus(function(){
$(this).attr('type','password');
});
- // We can't allow the type property to be changed (since it causes problems in IE)
- if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
- jQuery.error( "type property can't be changed" );
- }
// We can't allow the type property to be changed (since it causes problems in IE)
if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
jQuery.error( "type property can't be changed" );
}
- $("#pwd").focus(function(){
- $("#pwd")[0].type = 'password';
- $("#pwd").val("");
- });
$("#pwd").focus(function(){
$("#pwd")[0].type = 'password';
$("#pwd").val("");
});
- $("#showPwd").focus(function(){
- alert($("#showPwd")[0].type);
- $("#showPwd")[0].type = 'password';
- $("#showPwd").val("");
- });
$("#showPwd").focus(function(){
alert($("#showPwd")[0].type);
$("#showPwd")[0].type = 'password';
$("#showPwd").val("");
});
- <input name="password" type="password" id="password" class="input" style="display: none;" />
<input name="password" type="password" id="password" class="input" style="display: none;" />
- $("#showPwd").focus(function() {
- var text_value = $(this).val();
- if (text_value == this.defaultValue) {
- $("#showPwd").hide();
- $("#password").show().focus();
- }
- });
- $("#password").blur(function() {
- var text_value = $(this).val();
- if (text_value == "") {
- $("#showPwd").show();
- $("#password").hide();
- }
- });
$("#showPwd").focus(function() {
var text_value = $(this).val();
if (text_value == this.defaultValue) {
$("#showPwd").hide();
$("#password").show().focus();
}
});
$("#password").blur(function() {
var text_value = $(this).val();
if (text_value == "") {
$("#showPwd").show();
$("#password").hide();
}
});
最终效果: 当输入框获得焦点的时,输入的内容显示为“****”;当失去焦点的时,内容为空时显示“密码”。
实例代码:
<script type="text/javascript">
function test(){
$("#showPwd").focus(function() {
var text_value = $(this).val();
var defv = this.defaultValue;
if (text_value == this.defaultValue) {
$("#showPwd").hide();
$("#password").show().focus();
}
});
$("#password").blur(function() {
var text_value = $(this).val();
if (text_value == "") {
$("#showPwd").show();
$("#password").hide();
}
});
}
function checkValue(obj){
if(obj.value==''){
obj.style.display='none';
document.getElementById('repassword_f').style.display='';
}
}
</script>
密码3:<input name="password" type="text" id="showPwd" tabindex="2" class="input" value="请输入密码" />
<input name="password" type="password" id="password" class="input" style="display: none;" />
<br/><br/>
密码5:<input type="text" id="repassword_f" value="请输入密码" onclick="this.style.display='none';document.getElementById('repassword').style.display='';document.getElementById('repassword').focus();"/>
<input name="repassword" type="password" id="repassword" onblur="checkValue(this);" style="display:none"/>

本文介绍了一种在Internet Explorer浏览器中实现密码输入框特殊显示效果的方法。通过使用两个输入框结合JavaScript来实现在输入框未获得焦点时显示默认文字,获得焦点后变为密码输入形式的功能。



3万+

被折叠的 条评论
为什么被折叠?



