简体   繁体   中英

Javascript populate HTML table given cell data

I have an html table with cells that can be edited when clicked on. I am trying to figure out the best method to change cell data in cells following an edited cell.

For example, say the table comes populated by random numbers or letters. When I changed a cell to "14" I want the cells after it to change automatically to 15, 16, 17,n+1..ect. Or if I entered "h" the following cells would change to i,j,k,l...z stopping at z.

The number one seems pretty easy as I could just create a loop and i++ for each cell. However, the letter one doesn't seem as simple. Would I need to create an alphabet array and find the edited cell letter within it then proceed to the end of the array inserting each into the follow cells?

This can actually be done with a fairly simple function call like this one:

function NextChar(c){
    return String.fromCharCode(c.charCodeAt(0) + 1);
}

where c is the alphabetic character that is entered into the cell, passed as a parameter.

I can see this question was done quite some time ago, so this answer is more for people who make come seeking answers later.

I would make arrays with character sequences as you said and use the jQuery.inArray() API to detect which sequence the edited cells content is in.

Check it out: http://api.jquery.com/jQuery.inArray/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM