jQuery change input type

后端 未结 10 604
终归单人心
终归单人心 2020-12-01 04:24

Trying to change input type attribute from password to text.

$(\'.form\').find(\'input:password\').attr({type:\"text\"         


        
相关标签:
10条回答
  • 2020-12-01 05:09

    my solution:

        $('#myinput').clone().attr('type','tel').insertAfter('#myinput').prev().remove();
    
    0 讨论(0)
  • 2020-12-01 05:12

    It's 2018 and jQuery does support this feature now. The following will work:

    $('.form').find('input:password').attr("type","text");
    
    0 讨论(0)
  • 2020-12-01 05:15

    This is pretty easy thou. This works pretty fine.

     $('#btn_showHide').on('click', function() {
        if($(this).text() == 'Show')
        {
          $(this).text('Hide');
          $('#code').attr('type', 'text');
        }
        else
        {
          $(this).text('Show');
          $('#code').attr('type', 'password');
        }
      });
    
    0 讨论(0)
  • 2020-12-01 05:16

    I know I'm a little late to the game, but I was just able to do this in IE9 (it appears that Microsoft decided to allow it?). However, I had to do it with straight JavaScript. This is just a sample of a form with a dropdownlist that changes the field type depending on what is selected in the dropdown.

    function switchSearchFieldType(toPassword) {
        $('#SearchFieldText').val('');
        if (toPassword === true) {
            $('#SearchFieldText').get(0).setAttribute('type', 'password');
        } else {
            $('#SearchFieldText').get(0).setAttribute('type', 'text');
        }
    }
    
    $('#SelectedDropDownValue').change(function () {
        if ($("select option:selected").val() === 'password') {
            switchSearchFieldType(true);
        }
        else {
            switchSearchFieldType(false);
        }
    }).change();
    
    0 讨论(0)
提交回复
热议问题