I use this context menu for a right click on table:tr elements: http://www.downloadjavascripts.com/list/javasitelll99/Details.aspx
It works fine! and I defined a function for action handling.
var option = { width: 150, items: [
{ text: "Edit", icon: "public/images/sample-css/wi0126-16.gif", alias: "1-1", action: menuAction },
{ text: "Activate", icon: "public/images/sample-css/ac0036-16.gif", alias: "1-2", action: menuAction },
//this is normal menu item, menuAction will be called if this item is clicked on
{ text: "Deactivate", icon: "public/images/sample-css/ei0021-16.gif", alias: "1-3", action: menuAction },
//this is a split line
{ type: "splitLine" },
//this is a parent item, which has some sub-menu items
{ text: "Delete", icon: "public/images/sample-css/ei0021-16.gif", alias: "1-3", action: menuAction },
{ type: "splitLine" },
{ text: "Item Four", icon: "public/images/sample-css/wi0124-16.gif", alias: "1-5", action: menuAction },
{ text: "Group Three", icon: "public/images/sample-css/wi0062-16.gif", alias: "1-6", type: "group", width: 180, items: [
{ text: "Item One", icon: "public/images/sample-css/wi0096-16.gif", alias: "4-1", action: menuAction },
{ text: "Item Two", icon: "public/images/sample-css/wi0122-16.gif", alias: "4-2", action: menuAction }
]
}
]
};
function menuAction(){
alert(this.data.alias);
}
But, now I want to get the id of the clicked table:tr element. How to get it?
var myElementId;
var option = { ...
onShow: applyrule,
onContextMenu: BeforeContextMenu
};
function menuAction() {
alert(myElementId);
}
function applyrule(menu) {
myElementId = this.id
}
Assuming that tableId is the id of your table this function should help you:
function getIdOfRowByIndex(tableId, rowIndex) {
return document.getElementById(tableId).rows[rowIndex].id;
}
If you have a tr element, then this function should help you:
function getIdOfRow(trElement) {
return trElement.id;
}
You can use jQuery to simplify your tasks, but these functions are technology-agnostic to help those who do not want/can use jQuery too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.