HTML attribute contenteditable that specifies whether the content of an element is editable

黄舟
Release: 2017-11-03 10:04:18
Original
3065 people have browsed it

Example

An editable paragraph:

这是一个可编辑的段落。

Copy after login

Browser support


##IE

Firefox

Chrome

Safari

Opera


##All major browsers support the contenteditable

attribute

.Definition and usage

The contenteditable attribute specifies whether the content of the element is editable.

Note: If the element does not set the contenteditable attribute, the element will inherit this attribute from its parent element.

Differences between HTML 4.01 and HTML5

The contenteditable attribute is new in HTML5.

Syntax

Copy after login

Attribute value

Value true false In HTML, the cursor is an object, and the cursor object only appears when you select an element.
Description
Specifies that the element is editable.
Specifies that the element cannot be edited.

When we click on an input box, it will actually generate a selection object - selection (that is, the area where the text we can see turns blue), selection is in

Firefox The tool

can be obtained directly using window.getSelection(). In HTML, there is only one selection, and selection is an area. You can imagine it as a rectangle, which has a beginning and an end.When When you click on an input box or switch to another input box, the selection will change accordingly. The cursor is inside the selection. The cursor is called range. It is a fragment area. Like selection, it has a starting point and an ending point. When we press the left button on the text and pull it to the right, we will see that the text turns blue. That is the start and end of the cursor. When we click directly, the cursor flashes, but in fact it is just the start and end points that overlap.

OK, now let’s actually operate the cursor. Just look at the complete code and see the effect.

   
 
Copy after login

The above is the detailed content of HTML attribute contenteditable that specifies whether the content of an element is editable. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!