Swapping rows in JQuery

前端 未结 10 1620
后悔当初
后悔当初 2020-12-08 19:58

If I have a table as shown below, and have a up and down arrow that moves rows up and down, how would I go about swapping rows in JQuery?



        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 20:24

    I would try:

    var tmp = $ ('#Row1')
    $ ('#Row1').remove
    $ ('#Row2').after ($ ('#Row1'))
    

    But I guess it’s better to swap rows’ contents instead of swapping rows themselves, so that you can rely on numbering. Thus,

    var tmp = $ ('#Row1').html ()
    $ ('#Row1').html ($ ('#Row2').html ())
    $ ('#Row2').html (tmp)
    

提交回复
热议问题