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
I recently upgraded MySQL to 5.7, and WordPress r...
<br />Choose the most practical one to talk ...
This article shares the specific code of jquery+A...
Table of contents Overview Implementation Protect...
Table of contents Preface How to use Summarize Pr...
This article introduces the sample code of CSS pi...
1. Introduction Vagrant is a tool for building an...
1. Discover the problem © is the copyrigh...
This article example shares the specific code of ...
1. What problems did we encounter? In standard SQ...
This article uses examples to describe the common...
Windows 10 1903 is the latest version of the Wind...
background I am learning nodejs recently, and I r...
About Recently, in the process of learning Vue, I...
CSS naming rules header: header Content: content/c...