change type of input field with jQuery

后端 未结 29 2156
青春惊慌失措
青春惊慌失措 2020-11-22 05:13
$(document).ready(function() {
    // #login-box password field
    $(\'#password\').attr(\'type\', \'text\');
    $(\'#passwo         


        
29条回答
  •  -上瘾入骨i
    2020-11-22 05:28

    Simple solution for all those who want the functionality in all browsers:

    HTML

    
    
    Hide password
    

    jQuery

    $("#passwordSwitch").change(function(){
        var p = $('#password');
        var h = $('#passwordHide');
        h.val(p.val());
        if($(this).attr('checked')=='checked'){
            h.hide();
            p.show();
        }else{
            p.hide();
            h.show();
        }
    });
    

提交回复
热议问题