Home > Web Front-end > JS Tutorial > A good way to copy a table on a web page through js script_javascript skills

A good way to copy a table on a web page through js script_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:22:10
Original
1132 people have browsed it

Someone asked me a question today: How to copy a table on a web page through js script? It seems to be more difficult, but I still got it done. By the way, I recorded the process of solving this problem. I hope it will be helpful to the brothers who write scripts.

I have never written this kind of script before, but I remembered that I saw a script not long ago that can select all the contents of the HTML editor, so I thought of a plan: use a script to insert the table into the HTML editor. Then select all the content in the HTML editor and execute the copy command of the HTML editor to realize the copy table function and get it done quickly:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute it
]

This function is realized , but I feel a little unhappy because I have to use the HTML editor. However, from the code of the HTML editor, I noticed the createTextRange() method. This method has been used before, but I have never studied it in depth. In Msdn, I found that only objects such as Body and TextArea support the createTextRange() method. I continued to check it carefully in msdn. CreateTextRange() returns a TextRange object. I continued to check the TextRange object and found that it has many methods. I gave it a try first. findText method, I found that I could only select text but not objects. I continued to search and finally found that moveToElementText was the method we were looking for:
Text
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template