Placeholder in contenteditable - focus event issue

后端 未结 11 2103
无人共我
无人共我 2020-12-07 10:05

I have been trying to ask this before, without any luck of explaining/proving a working example where the bug happens. So here is another try:

I’m trying to replicat

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 10:52

    In .css

    .holder:before {
        content: attr(placeholder);
        color: lightgray;
        display: block;
        position:absolute;    
        font-family: "Campton", sans-serif;
    }
    

    in js.

    clickedOnInput:boolean = false;
    charactorCount:number = 0;
    let charCount = document.getElementsByClassName('edit-box')[0];
    
    if(charCount){
    this.charactorCount = charCount.innerText.length;
    }
    
    if(charactorCount > 0 && clickedOnInput){
    document.getElementById("MyConteditableElement").classList.add('holder');
    }
    
    if(charactorCount == 0 && !clickedOnInput){
    document.getElementById("MyConteditableElement").classList.remove('holder');
    }
    
    getContent(innerText){
      this.clickedOnInput = false;
    }
    

    In .html

    this solution worked for me in angular project

提交回复
热议问题