<table id="table1" width="300" class="table_border">
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>年龄</th>
    </tr>
     <tr>
        <td>1</td>
        <td>张三</td>
        <td>18</td>
    </tr>
    <tr>
        <td>2</td>
        <td>三娘</td>
        <td>18</td>
    </tr>
</table>
jquery实现:   $(function()
     {      
        $("#table1 th").mousedown(function(){
            var thstart,thend,the_txt;
            thstart=$("#table1 th").index(this);
            gettd(this)
         })
     })
    function gettd(obj)
    {
        var thstart,thend,the_txt;
         $("#table1 tr:first").sortable({
     })
     $(obj).mousemove(function(){
        thstart=$("#table1 th").index(this);
            the_txt=$(this).text();
            alert(the_txt)
     }) 
    }问题描述:当我拖动th时,我已经可以保存好我正在拖动的索引值和里面的内容,现在我想在我鼠标释放的时候去找到我刚才拖动的th,并保存它当前的索引值,也就是thstart和thend,该怎么做?
凡是回复的都有分,不够再加,对我解决问题有帮助的,重分酬谢!

解决方案 »

  1.   

    mousedown的时候最好this.setCapture()
    然后再加句$(this).data("offset",{thstart:thstart,thend:thend});拿的时候.由于触发事件的还是原来的对象.所以可以用
    $(this).data("offset").thstart
    $(this).data("offset").thend
    取值
      

  2.   

       $(function()
         {      
            $("#table1 th").mousedown(function(){
                this.setCapture(); 
                var thstart,thend,the_txt;
                thstart=$("#table1 th").index(this);
                $(this).data("offset",{"thstart":thstart,"thend":thend}); 
                gettd(this)
             }).mouseup(function(){
                this.releaseCapture(); 
                var thstart,thend,the_txt;
                thstart=$(this).data("offset").thstart; 
                thend=$(this).data("offset").thend; 
                alert(thstart);
                alert(thend);         });
         })
        function gettd(obj)
        {
            var thstart,thend,the_txt;
             $("#table1 tr:first").sortable({
             })
             $(obj).mousemove(function(){
                thstart=$("#table1 th").index(this);
                the_txt=$(this).text();
                alert(the_txt)
             }) 
        }试试可以么...
      

  3.   

    thend 是undefined,不行
      

  4.   

    我感觉好像逻辑有的问题,我想应该是mouseup以后才去取才对,因为如果数遍没释放,鼠标拖放的对象还没有定位,所以总是找不到,不知道是不是这样
      

  5.   

    因为前面theend放进去的时候没值...
    thstart有吧?
    嗯...theend要up的时候拿吧...
      

  6.   

     对thstart有值,thend总是undefined
      

  7.   

                var thstart,thend,the_txt;
                thstart=$("#table1 th").index(this);
                $(this).data("offset",{"thstart":thstart,"thend":thend}); 
    因为这时还没值...
                var thstart,thend,the_txt;
                thstart=$("#table1 th").index(this);
                thend=thstart;
                $(this).data("offset",{"thstart":thstart,"thend":thend}); 
    就有值了.