Home > Web Front-end > JS Tutorial > jQuery implementation of rising, falling, deleting, adding a line of code method sharing

jQuery implementation of rising, falling, deleting, adding a line of code method sharing

小云云
Release: 2018-01-23 14:04:59
Original
2098 people have browsed it

This article mainly introduces the jQuery implementation method of rising, falling, deleting, and adding a line of code. It is very good and has reference value. Friends in need can refer to it. I hope it can help everyone use jQuery better.

Application scenarios:

Multi-value sorting, classification sorting and other operations

This code is implemented after practice, and the implementation method is simple and Will not be lost (js adds a line of manually filled Input value) input value

Depends on Jquery, does not rely on other extensions

Javascript code


/*
addTableRow 为添加一行按钮的id值
tableAttr 为table的id值
*/
$(function(){
 //添加一行
 $('#addTableRow').on('click',function(e){
  e.preventDefault();
  var _Html = &#39;<tr><td><input type="text" placeholder="" class="input-text" value=""></td>&#39;
    + &#39;<td><a class="sortUp"><i class="Hui-iconfont"></i>上升</a> <a class="sortDown"><i class="Hui-iconfont"></i>下降</a> <a class="sortDel"><i class="Hui-iconfont"></i>删除</a></td></tr>&#39;;
  $(&#39;tbody&#39;, $(&#39;#tableAttr&#39;)).append(_Html);
  bindEvent();
 });
 bindEvent();
});
function bindEvent(){
 $(&#39;.sortDel,.sortUp,.sortDown&#39;).off();
 $(&#39;.sortDel&#39;).on(&#39;click&#39;, function(e) {
  e.preventDefault();
  if (confirm("确定要删除该属性?")) {
   $(this).parents(&#39;tr&#39;).remove();
  }
 });
 // 初始化上升按钮
 $(&#39;.sortUp&#39;).on(&#39;click&#39;, function(e) {
  e.preventDefault();
  var _current = $(this).parents(&#39;tr&#39;);
  if(($(&#39;tr&#39;).index(_current) - 2) >= 0) {
   _current.insertBefore(_current.prev());
  } else {
   alert("已经到顶了");
  }
 });
 // 初始化下降按钮
 $(&#39;.sortDown&#39;).on(&#39;click&#39;, function(e) {
  e.preventDefault();
  var _current = $(this).parents(&#39;tr&#39;);
  _current.insertAfter(_current.next());
 });
}
Copy after login

Achieve the effect

##Related recommendations:


JQuery simple method to implement traversal of radio button boxes

About jquery to obtain all value and text examples of select, option

JQuery design idea example sharing


The above is the detailed content of jQuery implementation of rising, falling, deleting, adding a line of code method sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template