Jquery implements label move-up, move-down, and top-down
Jquery implements label move-up, move-down, and top-down
This article mainly introduces jquery's information about label moving up, moving down, and top-down. It is provided with examples, which are very practical. For more information, see
For example, in the tag list in the background, the options include move up, move down, and top down.
The main implementation idea is node operations, such as moving up, directly moving the click item to the previous node, and so on. Of course, some judgment should be added to the actual code implementation, for example, if the current click operation item is set to a bottom or a base, a prompt is provided to let the operator know what has happened.
Ideas:
1. clone (true ):
That is, the items to be moved are saved first and used later.
2. Find the related elements corresponding to the current tag and their related methods:
For example:. prev () labels on the current element
. Next () Labels under the current element
Add a method after. after () xxx
Add method before. before () xxx
. Prepend add Method
3. Implementation
The specific code is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Var productsLabel = { // Set the pin to top SetHot: function (t ){ Var bar = 'showandhide _ box '; Var obj = $ (t). parents ('.' + bar). clone (true ); $ (T). parents ('.' + bar). remove (); $ (". ShowAndHide_list_box"). prepend (obj ); }, // Set up Move-up SetUp: function (t ){ Var bar = 'showandhide _ box '; If ($ (t). parents ('.' + barri.prev('.'{bar}.html ()! = Undefined ){ Var obj = $ (t). parents ('.' + bar). clone (true ); $ (T). parents ('.' + bar). prev (). before (obj ); $ (T). parents ('.' + bar). remove (); } Else { Alert ('Kiss, it's already the top one. You can't move it up again ...'); } }, // Set move down SetDown: function (t ){ Var bar = 'showandhide _ box '; If({(t}.parents('.'{bar}.next('.'{bar}.html ()! = Undefined ){ Var obj = $ (t). parents ('.' + bar). clone (true ); $ (T). parents ('.' + bar). next (). after (obj ); $ (T). parents ('.' + bar). remove (); } Else { Alert ('dear, it is now the bottom, and you cannot move it down ...'); } } } |
The above is all the content shared in this article. I hope you will like it.