Replace text with stars (*) in html with directives in angularjs

爱⌒轻易说出口 提交于 2019-12-20 03:52:25

问题


I need a textarea control with mask able property, if the textarea is mask able then the text should appear as stars instead of actual text.

I can have any no of textareas in my form, So i can't save actual text in other variable and save the stars or dots for actual textarea.

Can somebody help me to solve this issue?


回答1:


As others have already pointed out, it's not possible and should not be done. But here is something which you should give a try. If you really want to achieve it, you'll have to compromise on something. Use contenteditable div instead of input and use following CSS:

Demo: http://jsfiddle.net/GCu2D/793/

CSS:

.checked {
    font-size:20px;
    position:relative;
    display:inline-block;
    border:1px solid red;
}
.checked:before {
    font-size: inherit;
    content:" ";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    background-color: #FFF;
    width: 100%;
    background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Asterisk.svg/32px-Asterisk.svg.png");
    background-repeat: repeat-x;
    z-index: 1;
    background-size: 12px;
    background-position: left center;
}

HTML:

<div contenteditable class="checked">Sample Text</div>

Obviously, this is not a perfect solution, but you can start from here.

Note: You will need to adjust the font-size and the image used. Both dimensions needs to be in sync. Ofcourse you can change the size of image using background-size . Border here is just for visual feedback. If you need to adjust the width of the stars, then you may use calc() and play around with the exact dimension.



来源:https://stackoverflow.com/questions/31604402/replace-text-with-stars-in-html-with-directives-in-angularjs

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