Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Properties and usage of contenteditable in html5

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the properties and usage of contenteditable in html5". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the properties and usage of contenteditable in html5".

How to use contenteditable

Method 1:

one

Method 2: based on css

1user-modify:read-write-plaintext-only

2-webkit-user-modify:read-write-plaintext-only

If we are in a non-webkit kernel, we need to consider using js to implement it. The first thing that comes to mind is:

1vard=document.getElementById ("content")

2document.addEventListener ("keydown", function () {

3D [XSS _ clean] = d [XSS _ clean] .replace (/] * > / g, "")

4})

It is found that the effect is roughly the same as above, although it can filter the style, but there are many problems, such as the cursor is always in the first position, the input box can not insert facial expressions, newline failure and so on. Check the Internet to find out how others do it and find that you can filter the style by modifying the copy event:

Contenteditable code

1functionpasteFilter (e) {

2e.preventDefault ()

3vartext=null

4max / get the text in the clipboard

5if (window.clipboardData&&clipboardData.setData) {

6//IE

7text=window.clipboardData.getData ('text')

8} else {

9try {

10text= (e.originalEvent | | e) .clipboardData.getData ('text/plain')

11} catch (e) {

12return

13}

14}

Thank you for your reading, the above is the content of "the properties and usage of contenteditable in html5". After the study of this article, I believe you have a deeper understanding of the properties and usage of contenteditable in html5. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report