Toggle insert/delet the password display when applied to checkbox



  • It doesn't work, why?

    $('.passwordview input[type=checkbox]').click(
        function(){
        $('.password').attr('type', 'text' )
    },
        function(){
            $('.password').attr('type', 'password' );
    }
    );
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    

    <div class="form-order">
    <input type="text" value="Введите имя">
    <input type="password" class="password" value="Пароль">
    <div class="passwordview"><input type="checkbox"><span>Показать/скрыть пароль</span></div>

    </div>

    The chequebox must display the password when re-clicked, the password must be hidden.



  • Your function doesn't work because you're transferring two functions to the processor as arguments while, according to the documentation, it only takes one.

    Try doing this: https://jsfiddle.net/3er345a5/

    js:

    $('.passwordview input[type=checkbox]').on('change', function() {
        var $el = $(this);
        if ($el.is(':checked')) {
        $('.password').attr('type', 'text');
        } else {
        $('.password').attr('type', 'password');
        }
    });
    

    html

    <div class="form-order">
        <input type="text" value="Введите имя">
        <input type="password" class="password" value="Пароль">
        <div class="passwordview"><input type="checkbox"><span>Показать/скрыть пароль</span></div>
    

    </div>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2