问题
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