您好,欢迎访问一九零五行业门户网

JQuery操作table中tr的位置

这次给大家带来jquery操作table中tr的位置,jquery操作table中tr的位置的注意事项有哪些,下面就是实战案例,一起来看一下。
表格样式
<table>   <tr>     <td><input type="button" value="上移" onclick="moveup(this)"/></td>     <td><input type="button" value="下移" onclick="movedown(this)"/></td>   </tr>   <tr>     <td><input type="button" value="上移" onclick="moveup(this)"/></td>     <td><input type="button" value="下移" onclick="movedown(this)"/></td>   </tr>     <tr>     <td><input type="button" value="上移" onclick="moveup(this)"/></td>     <td><input type="button" value="下移" onclick="movedown(this)"/></td>   </tr> </table>
js代码
// 上移  function moveup(obj) {    var current = $(obj).parent().parent(); //获取当前<tr>   var prev = current.prev();  //获取当前<tr>前一个元素   if (current.index() > 0) {      current.insertbefore(prev); //插入到当前<tr>前一个元素前   }  }  // 下移  function movedown(obj) {    var current = $(obj).parent().parent(); //获取当前<tr>   var next = current.next(); //获取当前<tr>后面一个元素   if (next) {      current.insertafter(next);  //插入到当前<tr>后面一个元素后面   }  }
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery的插件怎么打印页面内容
jquery运行页面怎样默认触发点击事件
layui中的树形关于取值传值详解
以上就是jquery操作table中tr的位置的详细内容。
其它类似信息

推荐信息