change type of input field with jQuery

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


        
29条回答
  •  孤独总比滥情好
    2020-11-22 05:46

    Just another option for all the IE8 lovers, and it works perfect in newer browsers. You can just color the text to match the background of the input. If you have a single field, this will change the color to black when you click/focus on the field. I would not use this on a public site since it would 'confuse' most people, but I am using it in an ADMIN section where only one person has access to the users passwords.

    $('#MyPass').click(function() {
        $(this).css('color', '#000000');
    });
    

    -OR-

    $('#MyPass').focus(function() {
        $(this).css('color', '#000000');
    });
    

    This, also needed, will change the text back to white when you leave the field. Simple, simple, simple.

    $("#MyPass").blur(function() {
        $(this).css('color', '#ffffff');
    });
    

    [ Another Option ] Now, if you have several fields that you are checking for, all with the same ID, as I am using it for, add a class of 'pass' to the fields you want to hide the text in. Set the password fields type to 'text'. This way, only the fields with a class of 'pass' will be changed.

    
    
    $('[id^=inp_]').click(function() {
        if ($(this).hasClass("pass")) {
            $(this).css('color', '#000000');
        }
        // rest of code
    });
    

    Here is the second part of this. This changes the text back to white after you leave the field.

    $("[id^=inp_]").blur(function() {
        if ($(this).hasClass("pass")) {
            $(this).css('color', '#ffffff');
        }
        // rest of code
    });
    

提交回复
热议问题