jQuery change input type

后端 未结 10 744
终归单人心
终归单人心 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: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();
    

提交回复
热议问题