我有一个有很多行的表格。表在那里,所以人们可以通过复制/粘贴来快速获取数据。问题是你很容易忘记你最后一次从哪里抓取文本(即。哪一行)。所以我想要一个函数,当你双击一行(以突出显示一些要复制的文本)时,它只会突出显示该行,并保持突出显示,直到再次双击。
我非常喜欢使用Jquery。
这是我到目前为止所得到的:
$("tr").dblclick ( function() {
var foo = (this);
$(foo).css("background-color","#333");
$(foo).css("color","white");
});
$("tr").mouseleave ( function() {
var foo = (this);
$(foo).css("background-color","#333");
$(foo).css("color","white");
});双击可以正常工作。但是鼠标离开会高亮显示每一行。我可以将一个变量赋给我双击的那一行,然后只对其应用.mouseleave函数吗?或者有没有更适合我想要的功能。
谢谢。
发布于 2013-05-27 12:37:35
$("tr").dblclick ( function() {
// Unselect the previous selected row Logic
$(this).siblings().removeClass("Clicked");//Assuming the <tr> are at same level.
//$(this).parent().children("tr").not(this).removeClass(".Clicked");
$(this).toggleClass("Clicked");
});并将$("tr").mouseleave ( function() {});更改为$("document").on( "mouseleave","tr.Clicked",function() {});
另外,有像这样的css也很好-
.Clicked{
background-color : #333;
color : white;
}发布于 2013-05-27 12:38:15
您可以添加一个标志来标识双击哪个标志。如果标志为true,则只应用mouseleave函数。
如果在这种情况下分配事件,还必须应用delegation方法。像所有的tr或所有的li。
另外,我不明白mouseleave事件的含义,因为你正在做和dblclick事件一样的事情。
var allTr=$('#tableId').find('tr');
$('#tableId').on('.dblclick','tr',function() {
var foo = $(this);
//to remove css and attribute from privous selected tr
allTr.css({"background-color","#333","color","white"}).removeData('clicked')
//if you want to remove css when you double click again on same tr than use this if condition other wise dont use.
if(!foo.data('clicked')){
foo .css({"background-color","#333","color","white"}).data('clicked',true);
}
}).on('mouseleave','tr',function() {
var foo = $(this);
if(foo.data('clicked')){
foo .css({"background-color","#333","color","white"});
}
});发布于 2013-05-27 13:23:36
https://stackoverflow.com/questions/16766240
复制相似问题