How to make an HTML
element editable cross-browser?

前端 未结 4 636
独厮守ぢ
独厮守ぢ 2020-11-30 20:04

Do you know how to make a

editable with JavaScript? I\'m looking for cross-browser solution.

Something similar to a rich text area, but that

相关标签:
4条回答
  • 2020-11-30 20:46

    You can do this in pure HTML

    <div class="editable" contenteditable="true">
        Editable text...
    </div>
    

    Hope this helps!

    0 讨论(0)
  • 2020-11-30 20:51

    Set contentEditable property of the element to "true":

    element.contentEditable = "true";
    

    See also:

    • Content Editable MDN docs
    • Browser support on caniuse.com
    0 讨论(0)
  • 2020-11-30 20:53
    How about his: 
    

    Make a hidden "textArea" , and upon selecting(clicking or Hover) the div , hide the Div and Show the textArea .

    0 讨论(0)
  • 2020-11-30 21:03

    I found out how.

    You use the contentEditable property of the DOMElement, like so

    <div onClick="this.contentEditable='true';">
        lorem ipsum dolor lorem ipsum dolorlorem ipsum dolor
    </div>
    
    0 讨论(0)
提交回复
热议问题