选择第一个子节点jquery

$("table tr:first-child")

a=$("table tr:eq(1)")

$(a).before($("table tr:eq(3)"))

 

 

以下是一个实现向上移,最上,最下,向下移的一个排序加上checkbox全选 反选 的操作

最近发现jquery写代码快起来了,可能真是写得多了有点熟番起来了

<%=flash[:info] unless flash[:info].nil?%>

这个界面是批量来处理产品展示中产品的选择排序的问题

<!--<form id="form1" name="form1" method="post" action="/admin/products/batch_select">-->

    <%=form_for(["admin",@product],:id=>"form1") do |f|%>

               <input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">

 

    <input type="text" name="product_show_id" value="<%=params["product_show_id"] || @product_show.id%>" />

    <%= f.label :name %>

    <%= f.text_field :name %>

 

    <input id="query" type="button" name="query" value="查询" data="/admin/product_shows/batch_select?act=query" />

 

    <input id="select_all" type="checkbox" />全选

    <input id="select_reverse" type="checkbox" />反选

 

    <input id="load" type="button" name="load" value="载入" data="/admin/product_shows/batch_select?product_show_id=<%=params["product_show_id"] || @product_show.id%>" />

    <input id="add" type="button" name="add" value="加入" data="/admin/product_shows/batch_select?act=add" />

    <input id="overwrite" type="button" name="overwrite" value="覆盖" data="/admin/product_shows/batch_select?act=overwrite" /><br/>

 

        共有<%=@products.size%>条记录

 

        <table>

  <tr>

    <th></th>

    <th>pic</th>

    <th>Id</th>

    <th>Name</th>

    <th>P1</th>

    <th>P2</th>

    <th>P3</th>

    <th>P4</th>

    <th>Promotion</th>

    <th>New</th>

    <th>Score</th>

    <th>S1</th>

    <th>Description</th>

    <th></th>

    <th></th>

    <th></th>

    <th></th>

    <th></th>

    <th></th>

    <th></th>

  </tr>

 

<% @products.each do |product| %>

  <tr>

    <td><input name="product_id[]" type="checkbox" value="<%=product.id%>" /></td>

    <td><%=image_tag product.i1.url(:thumb)%></td>

    <td><%= product.id %></td>

    <td><a href="<%=myproduct_url(product.id)%>" target="_blank"><%= product.name %></a></td>

    <td><%= product.p1 %></td>

    <td><%= product.p2 %></td>

    <td><%= product.p3 %></td>

    <td><%= product.p4 %></td>

    <td><%= product.promotion %></td>

    <td><%= product.new %></td>

    <td><%= product.score %></td>

    <td><%= product.s1 %></td>

    <td></td>

    <td><%= link_to 'Show', admin_product_path(product) %></td>

    <td><%= link_to 'Edit', edit_admin_product_path(product) %></td>

    <td><%= link_to 'Destroy', admin_product_path(product), :confirm => 'Are you sure?', :method => :delete %></td>

    <td><input type='button' name='top' value='top' /></td>

    <td><input type='button' name='higher' value='higher' /></td>

    <td><input type='button' name='lower' value='lower' /></td>

    <td><input type='button' name='bottom' value='bottom' /></td>

  </tr>

<% end %>

</table>

<!--</form>-->

<%end%>

<script type="text/javascript">

  $("input[name='top']").click(function(){

      var a=$("table tr:eq(1)");

     var current=$(this).parents("tr");

     //alert(a.html());

     //alert(current.html());

      $(a).before(current);

    })

  $("input[name='bottom']").click(function(){

      var a=$("table tr:last");

     var current=$(this).parents("tr");

     //alert(a.html());

     //alert(current.html());

      $(a).after(current);

    })

  $("input[name='higher']").click(function(){

 

     var current=$(this).parents("tr");

     //alert(current.html());

     //alert($("table tr:eq(1)").html());

     if (current.html()!=$("table tr:eq(1)").html())

     {

      current.prev().before(current)

     }

     else

     {

        alert("到顶了");

     }

     //alert(a.html());

     //alert(current.html());

      //$(a).after(current);

    })

  $("input[name='lower']").click(function(){

      var a=$("table tr:last");

     var current=$(this).parents("tr");

      if (current.html()!=$("table tr:last").html())

      {

      current.next().after(current);

      }

      else

      {

        alert("到底了");

      }

    })

    $("#select_all").click(function(){

        //alert($(this).attr("checked"));

        $("input[name='product_id[]']").attr("checked",$(this).attr("checked"));

        });

    $("#select_reverse").click(function(){

        $("input[name='product_id[]']").each(function(idx,item){

            $(item).attr("checked",!$(item).attr("checked"));

 

            });})

 

    $("#add").click(function(){

 

        $("form").attr("action",$(this).attr("data"));

 

        $("form").submit();

 

        })

    $("#overwrite").click(function(){

 

        $("form").attr("action",$(this).attr("data"));

 

        $("form").submit();

 

        })

    $("#load").click(function(){

 

        window.location.href=$(this).attr("data")+"&m="+Math.random();

 

 

        })

    $("#query").click(function(){

 

        $("form").attr("action",$(this).attr("data"));

        $("form").submit();

        })

</script>

posted on 2011-01-29 13:24  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2011/01/29/1947447.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值