我想在table中,如果用户将鼠标放在用动画着色的每一行上,当鼠标移出时,行的颜色就会恢复为默认值。但是如果用户用鼠标右键单击行,该行将显示为红色,直到单击上下文菜单。
我尝试过此代码,但当用户右键单击并希望选择菜单项时,红色行返回到默认值,但我希望在单击( select )之前行为红色:
$(function () {
$('.users').contextMenu({
selector: 'tr',
callback: function (key, options) {
if (key == 'delete') {
if (confirm(" Are you sure?")) {
$.post("../Actions/Delete.ashx", { type: "user", id: $(this).attr('id') });
$(this).animate({ backgroundColor: '#FF80FF' }, 1000);
}
}
},
items: {
"edit": { name: "edit" },
"delete": { name: "delete" }
}
});
$('tr').mouseover(function () {
$('td', this).stop(true, true).animate
({ backgroundColor: "#80FF00" }, 300);
});
$('tr').mouseout(function () {
$('td', this).stop(true, true).animate
({ backgroundColor: "white" }, 300);
});
$('tr').mousedown(function (event) {
if (event.which==3) {
$('td', this).animate
({ backgroundColor: "red" }, 300);
}
});
});发布于 2013-06-11 18:36:18
使用clicked标志检查右键单击:
$(function () {
var clicked=false;
$('.users').contextMenu({
selector: 'tr',
callback: function (key, options) {
if (key == 'delete') {
if (confirm(" Are you sure?")) {
$.post("../Actions/Delete.ashx", { type: "user", id: $(this).attr('id') });
$(this).animate({ backgroundColor: '#FF80FF' }, 1000);
}
clicked=false;
}
},
items: {
"edit": { name: "edit" },
"delete": { name: "delete" }
}
});
$('tr').mouseover(function () {
$('td', this).stop(true, true).animate
({ backgroundColor: "#80FF00" }, 300);
});
$('tr').mouseout(function () {
if(!clicked){
$('td', this).stop(true, true).animate
({ backgroundColor: "white" }, 300);
}
});
$('tr').mousedown(function (event) {
if (event.which==3) {
clicked=true;
$('td', this).animate
({ backgroundColor: "red" }, 300);
}
});
});https://stackoverflow.com/questions/17038367
复制相似问题