Copy code The code is as follows:<div contenteditable="true">You can edit the content</div> If you add contenteditable="true" to BODY, you can find out how magical this attribute is. Therefore, we can set the contenteditable="true" attribute to the HTML tag to edit the tag. The contenteditable attribute is compatible with all browsers (the compatibility of versions prior to IE6 has not been tested). Sometimes we can use DIV instead of input or textarea to achieve the same effect. For example, when using ajax, we can get the content of DIV when submitting the form. Careful people will find that the text box for posting comments in QQ space is actually a DIV, not a textarea text box. How does Div+CSS simulate the textarea text field height adaptation to achieve the contenteditable attribute of the HTML5 standard This effect is mainly achieved by adding the contenteditable attribute in HTML5 to the tag (contenteditable: specifies whether the user is allowed to edit the content). The great thing is that IE will also support this attribute, so you don’t have to worry too much about compatibility issues. Copy code The code is as follows:<style type="text/css"> .demoEdit{border:1px solid #dddddd;width:450px;min- height:20px;_height:20px;outline:0px;padding:2px;} // outline:0px;Style solution: When the container gets the focus, the container will display the effect of a dotted frame in the FF browser. .demoEdit p{margin:0px;padding:0px;} </style> <div contenteditable="true" style="border:1px solid #dddddd;width:360px;min-height:20px;_height:20px;outline:0px;"></div> <div contenteditable="true" class="demoEdit"></div> Attachment: The contentEditable attribute in Html can turn on the editable state of certain elements. Maybe you have never used the contentEditable attribute, or even never heard of it, but the role of contentEditable is quite magical. You can make div or the entire web page, as well as span and other elements writable. The most commonly used text input elements are input and textarea. After using the contentEditable attribute, you can enter content in div, table, p, span, body, and many other elements. In particular, contentEditable has been effectively supported in the HTML5 standard. Come and witness it. After setting the contentEditable="true" attribute, isn’t it quite magical? Ha ha… Let's have a special effect. By opening the div element editing, can we insert a picture? This requires the use of js. Copy code The code is as follows:<script> function img(){ var location1 = prompt("Please enter the address of the picture:","http://"); if(location1){ selImg(location1); } } function selImg(s){ if(!s){return false;} var h=s.substr(s.lastIndexOf(".")+1,3); if(h=="gif"||h=="jpg" || h=="GIF" || h=="JPG"){ Edit = document.getElementById("idEdit") Edit.innerHTML+='<img src='+s+'>' } else{ } } </script> <div NAME=EditCtrl id=idEdit contentEditable=true style="width:100%;height:200px;border:1px solid #666666"> <b>Yuzi.me</b></div> <input type="button" name="Submit" value="Insert image" onclick="img()"> Awesome! If you want to use more effects, you need to write js code yourself. I hope all the siege heroes can give their best and look forward to sharing! |
<<: jQuery+swiper component realizes the timeline sliding year tab switching effect
>>: Study on using characters instead of pictures to achieve rounded or sharp corners
Table of contents 1. Event Flow 1. Concept 2. DOM...
In higher versions of Tomcat, the default mode is...
1. When the width of the adjacent floating layer o...
Preface: MYSQL should be the most popular WEB bac...
*Create a page: two input boxes and a button *Cod...
Table of contents 1. We must ensure that the vue/...
123WORDPRESS.COM--HTML超文本标记语言速查手册<!-- --> !D...
Table of contents Preface Instruction Basics Hook...
1. Command Introduction The ifconfig (configure a...
MySQL 8.0.25 decompression version installation t...
After the container is started Log in to admin fi...
Table of contents Preface 1. First completely uni...
1. Unzip MySQL 5.7 2. Create a new configuration ...
Gird layout has some similarities with Flex layou...
For example, when you create a new table or updat...