<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,该怎么做?
凡是回复的都有分,不够再加,对我解决问题有帮助的,重分酬谢!
然后再加句$(this).data("offset",{thstart:thstart,thend:thend});拿的时候.由于触发事件的还是原来的对象.所以可以用
$(this).data("offset").thstart
$(this).data("offset").thend
取值
{
$("#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)
})
}试试可以么...
thstart有吧?
嗯...theend要up的时候拿吧...
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});
就有值了.