我最近一直在研究一个小应用程序。我绝不是这方面的专业人士。我希望有一个jQuery UI菜单显示用户点击我的表格。问题是菜单永远不会显示在桌子上方,而是在下面(在下面,而不是在桌子的下面,而不是在桌子下面)。
$("table.selectTable").delegate("tr", "click", function(event) {
event.stopPropagation();
lastClicked = $(this);
var menu = '#' + $(this).parent().parent().attr('name') + 'Menu';
console.log(menu); //getting the result (the show and hide work as well)
$(menu).hide();
if (!event.shiftKey) {
if ($(this).children().hasClass("highlight")) {
console.log('event coords' + event.pageX + "," + event.pageY);
console.log($(this).offset());
//$(this).children().removeClass("highlight");
position = $(this).position();
if ($(menu).css('display') === 'none') {
$(menu).menu().position({
my: "right top",
of: event
});
$(menu).show();
} else {
console.log('no menu to show');
$(this).children().removeClass("highlight");
}
} else {
console.log('add');
$(this).parent().children().children().removeClass("highlight");
$(this).children().addClass("highlight");
}
} else {
if ($(this).children().hasClass("highlight")) {
$(this).children().removeClass("highlight");
} else {
$(this).children().addClass("highlight");
}
}
clearSelection();
});
这段丑陋且不再使用的代码工作: (太具体了,不是非常可重复使用,并且依赖于丑陋的复选框进行选择 - 突出显示只是为了显示与菜单相关的行)
$("#groupList tbody").delegate("tr", "click", function(event) {
lastClicked = $(this).children("td").next().html();
$(this).parent().children().children().removeClass("highlight");
event.stopPropagation();
if (event.target.nodeName !== "INPUT" && $(event.target).children("input").first().attr('rel') === undefined) {
$(this).children().addClass("highlight");
$("#gListMenu").menu().position({
my: "right top",
of: event
});
$("#gListMenu").show();
} else {
$("#gListMenu").hide();
}
});
我真诚地感谢任何人提供的任何意见,因为我已尽可能多地研究。