我希望有一个上下文菜单,右键单击特定单元格。
在html文件中,我通过编写
来链接脚本<script src="ContextMenuController.js"></script> // link the js file
<link rel="stylesheet" type="text/css" href="ContextMenuStyle.css"> // link the css file
在我的js文件中,我想通过编写
来创建这个上下文菜单$(this).closest('td').onmousedown = function(event) { // get the cell clicked on
if (event.which == 3) { // just build the menu on a right click
var contextElements = ["btnAddRowAbove", "btnAddRowBelow", "btnAddColumnLeft",
"btnAddColumnRight", "btnMoveRowUp", "btnMoveRowDown", "btnMoveColumnLeft",
"btnMoveColumnRight", "btnDeleteRow", "btnDeleteColumn", "btnUndo", "btnRedo"]; // store all the buttons of the menu
var menuText = "<ul class=\"contextmenu\">"; // the wrapper
for (var i = 0; i < contextElements.length; i++) {
menuText += "<li id= contextElements[i]> contextElements[i] <\/li>"; // append all the buttons to the wrapper
}
return menuText + "<\/ul>"; // finish the wrapper
}};
当我尝试使用alert()
进行调试时,代码甚至无法达到此功能。
有人可以帮助我吗?