"Original share" dynamic new row and delete row

Source: Internet
Author: User

because of a small need to work, to write this is very small, but novice friends may be a bit confusing features
remember just when the work done a similar function, but the idea is not very remember, only remember very messy, measured various bugs.

Take a look at this idea today, more suitable for novice friends, not a lot of jquery parent-child relationship

let's look at the approximate interface.


the implementation is to click on the new line will add a blank line, click Delete to delete the row, click Save to save the information

The verification aspect is simple, just the red does not allow the submission

1. First look at the main code of the initial page






is not very simple, the initialized page has only a separate blank line and two buttons plus two hidden fields

This small function, the only confusion may be to increase the number of deleted from the middle, will cause data confusion.
Here's how I deal with it, recording an initialized max maximum hidden field, which defaults to 0. Adding a row adds one to this value, removing the inconvenience, which guarantees that the generated dynamic ID is unique and better than the default sorting effect.
Since this requirement was added at the end of the line, it was relatively straightforward. If you have classmates to do new under a specific line, in addition to the ID does not duplicate also need to consider the problem of sorting.

Here's a look at the new JS code




the above is the new row and delete the specific line JS, is not very simple.

2. New Save Operation

since the business requirements were saved before a few checksums were made, just passing the data
There are actually a lot of ways to JSON, lists and so on. I am rather lazy. Oneself according to their own rules splicing string to pass, to the business processing of the place to parse out, only for everyone to refer to the next

First look at the code that parses the data, passing the ID of the row into the method


Save method There is nothing to say, there is a non-enabled feature to deal with here, the rest is to pass the data to the background processing and then return the results



The rest is back to the storage of those, very simple right, and then is if the function needs to be modified when there is a back to appear function, to see


3. To modify the echo operation
in fact, the above method of preservation has satisfied the requirements of the modification, then the only thing left is the Echo




here are a few 1. Because it is a shared page, the original empty row of Span0 is deleted before the data is initialized
2. New loop generated new row, ID and original, so that in the background to take care of the sorting of the data
3. Since the ID is saved, and our tag max is 0 on the newly opened page, we are going to calculate max at the same time as the data is loaded and put it back in the hidden field.

so this little function is basically done.


welcome everyone to exchange, study together, hope to give a little revelation to the new, master don't hack me haha.

article for original published inHttp://techfoxbbs.com/thread-21638-1-1.html. You are also welcome to pay attention to the public number Techfoxbbs, Exchange learning
Reprint Please indicate the source

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Original share" dynamic new row and delete row

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.