contenteditable="true"
. Under the tag can be almost everything: text with formatting, pictures, lists, and even flash-videos. But the user can only add text, he can only delete the rest. In this post I will show an example of using content editable on a website. <!DOCTYPE HTML> <html> <head> <title> HTML5</title> <script type="text/javascript">
buttonClick()
function handles a click on the Save button (Edit): the contentEditable
attribute contentEditable
, the inscription on the button and the contents of the list are copied into the text field. function buttonClick () { var div = document.getElementById ("myDiv"); var button = document.getElementById ("myButton"); var content_div = document.getElementById ("ListContent"); var textarea = document.getElementById ("myTextarea"); if (div.contentEditable == "true") { div.contentEditable = "false"; content_div.style.display = "inline"; textarea.innerHTML = div.innerHTML; button.value = ""; } else { div.contentEditable = "true"; content_div.style.display = "none"; button.value = ""; } } </script> </head> <body> <b> ?</b> ( )
div
. Pay attention to contenteditable="true"
. <div id="myDiv" contenteditable="true"> <ul id="todolist"> <li> </li> <li> </li> <li> </li> <li> !</li> </ul> </div>
buttonClick()
function is buttonClick()
. <input type="button" id="myButton" onclick="buttonClick();" value=""> <br><br>
<div id="ListContent" style="display: none;"> :<br> <textarea rows="10" cols="70" id="myTextarea"> </textarea> </div> </body> </html>
contenteditable
.Source: https://habr.com/ru/post/126877/
All Articles