2016-06-23 4 views
-1

Привет, я пытаюсь создать логин, все в порядке, но в моем пароле ввода. Я хочу, чтобы пробел, когда пользователь нажимает на него, показывает пароль, и когда вы нажимаете снова, скройте пароль на момент У меня есть только первый шаг (показать пароль).Как удалить и добавить тип ввода с помощью jQuery

Here is the code

ответ

2

Вы должны попробовать это:

$('#xd').on('mouseup', function() { 
    $('#Contraseña').attr('type', 'password') 
}); 

$('#xd').on('mousedown', function() { 
    $('#Contraseña').attr('type', 'text') 
}); 

Code here

1

Используйте этот код

$("button").click(function(){ 
 
    if ($("input").attr("type") == "password"){ 
 
     $("input").attr("type", "text"); 
 
     $(this).text("Hide password"); 
 
    } else { 
 
     $("input").attr("type", "password"); 
 
     $(this).text("Show password"); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="password" /> 
 
<button>Show password</button>

0

Вы можете просто создать переменную & сначала присвоить его false, теперь на смену мыши эту переменную true и установите переключатель в attr type

var shown=false; 
    $('#xd').click(function() { 
     shown=!shown; 
     $('#Contraseña').attr('type', shown ? 'text' : 'password') 
    }); 
0

Попробуйте это;)

<label for="pass_field_id">Password:</label> 
<input type="password" value="your_passowrd" name="password" id="pass_field_id" /> 
<a href="#" onclick="show_hide_password('pass_field_id');" id="showhide">Show</a> 

<script> 
function swapInput(tag, type) { 
    var el = document.createElement('input'); 
    el.id = tag.id; 
    el.type = type; 
    el.name = tag.name; 
    el.value = tag.value; 
    tag.parentNode.insertBefore(el, tag); 
    tag.parentNode.removeChild(tag); 
} 

function show_hide_password(target){ 
    var d = document; 
    var tag = d.getElementById(target); 
    var tag2 = d.getElementById("showhide"); 

    if (tag2.innerHTML == 'Show'){ 

     swapInput(tag, 'text'); 
     tag2.innerHTML = 'Hide'; 

    } else { 
     swapInput(tag, 'password'); 
     tag2.innerHTML = 'Show'; 
    } 
} 
</script> 
Смежные вопросы