


Set the contenteditable attribute to edit the content of HTML tags (can replace textarea)_HTML/Xhtml_Web page production
May 16, 2016 pm 04:37 PM<div contenteditable="true"> ;You can edit the content inside</div>
If you add contenteditable="true" to BODY, you can see how magical this attribute is. Therefore, we can set the contenteditable="true" attribute to the HTML tag and the tag can be edited.
The contenteditable attribute is compatible with all browsers (the compatibility of versions prior to IE6 has not been tested)
In some cases, we can use DIV to replace input or textarea to achieve the same effect. For example, when using ajax, we can get the content of the 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 Div CSS simulates textarea text area height adaptability to meet the HTML5 standard contenteditable attribute
This effect is mainly achieved by adding the contenteditable attribute in HTML5 to the tag (contenteditable: specifies whether users are allowed to edit content). What’s great is that IE also supports this attribute, so you don’t have to worry too much about compatibility issues.
DEMO:
<style type="text/css ">
.demoEdit{border:1px solid #dddddd;width:450px;min- height:20px;_height:20px;outline:0px;padding:2px;} // outline:0px; style resolution container gets focus When , the container will display the effect of a dotted box in the FF browser.
.demoEdit p{margin:0px;padding:0px;}
style="border:1px solid #dddddd;width:360px;min-height:20px;_height:20px;outline:0px;"></div>
<div contenteditable="true" class=" demoEdit"></div>
Under the FF browser, when the container gets focus, the height of the cursor will be the same as the height of the container or the cursor will not be displayed. At this time, if a placeholder is added to the container by default, such as <br /> or can solve this problem.
Now Yuzi will introduce to you another good method that is editable and can automatically adapt to the height without adding js code. Let everyone open their eyes. Yuzi can use DIV directly as a text box, similar to the TextArea text box. More importantly, the user experience of DIV is more perfect and handsome.
After setting the contentEditable="true" attribute, isn't it quite magical? Haha...
DEMO page:
http://demo.jb51.net/js/2014/ContentEditable/
function img (){
var location1 = prompt("Please enter the address of the image:","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()">

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?

How do I use HTML5 form validation attributes to validate user input?

How to efficiently add stroke effects to PNG images on web pages?

What is the purpose of the <iframe> tag? What are the security considerations when using it?

What is the purpose of the <datalist> element?

What is the purpose of the <meter> element?

What are the best practices for cross-browser compatibility in HTML5?

What is the purpose of the <progress> element?
