Is there a known way to have a textarea with the password type?

陌路散爱 提交于 2020-01-04 05:56:14

问题


So I am currently trying to get a textarea with the password type (actually like an input).

I've try to create my own font (with only black points) but it's a bit hard...

I've tried some Jquery but that was not concluant either.

Thanks for your help.


回答1:


This post: How to make a Textarea act like a password field

mentions using the keydown event to replace things in the box with whatever you want. Of course, you'll need to store the entered text in some javascript variable at the same time.




回答2:


I Hope you can get idea from

http://jsfiddle.net/X37Wz/6/

<textarea rows="10" cols="30" id="field"  onKeyPress="handleTyping(event)">
</textarea>

<textarea rows="10" cols="30" id="hiddenfield"  style="display:none">
</textarea>


function handleTyping(e){
    setTimeout(function(){handleTypingDelayed(e)},500);
}

function handleTypingDelayed(e){

    var text = document.getElementById('hiddenfield').value;
    var stars = document.getElementById('hiddenfield').value.length;
    unicode = eval(unicode);
    var unicode=e.keyCode? e.keyCode : e.charCode;

    if ( (unicode >=65 && unicode <=90) 
            || (unicode >=97 && unicode <=122) 
                || (unicode >=48 && unicode <=57) ){
        text = text+String.fromCharCode(unicode);    
        stars += 1;
    }else{
        stars -= 1;
    }

    document.getElementById('hiddenfield').value = text;
    document.getElementById('field').value = generateStars(stars);
}

function generateStars(n){
    var stars = '';
    for (var i=0; i<n;i++){
        stars += '.';
    }
    return stars;
}


来源:https://stackoverflow.com/questions/16058008/is-there-a-known-way-to-have-a-textarea-with-the-password-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!