Home >Web Front-end >JS Tutorial >Implementation code for inserting a row at a specified position in the JavaScript talbe table Script House revised version_javascript skills

Implementation code for inserting a row at a specified position in the JavaScript talbe table Script House revised version_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:51:341447browse

I'm learning JavaScript recently. Here's an example I made myself (based on the w3cschool example)
The function of this example is to insert a row after the row clicked by the mouse. The default is to insert it in the first row. You can enter the inserted content yourself, the code is as follows


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]
Implementation code for inserting a row at a specified position in the JavaScript talbe table Script House revised version_javascript skills

The above is the content, which is inserted at the beginning by default.
What needs to be noted here is that when the mouse clicks the insert row button, the action will also capture and change the global variable. I didn’t realize it at the beginning, that is, I didn’t add the above red code, so every time I clicked the insert row Insert in the first line. According to the original design, the global variable is changed to 0 when the button is clicked, so it can only be added in the first line.
The simple solution is to add red code, which can avoid the problem just now.
The above is just a small experience in the learning process. You can use it as a template to complete functions such as deleting a specified row or inserting before a specified row. Continue to learn JavaScript and continue to communicate.
Statement:
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