2014-02-22 1 views
0

를 클릭하세요! 나는 액션 핸들링을위한 함수를 정의했다.wdContextMenu 내가 테이블에 마우스 오른쪽 버튼으로 클릭이 상황에 맞는 메뉴를 사용하여 요소 ID

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); 
} 

하지만 이제는 클릭 한 테이블의 ID 인 tr 요소를 가져 오려고합니다. 어떻게 구할 수 있습니까? 당신이 그럴 요소가있는 경우

function getIdOfRowByIndex(tableId, rowIndex) { 
    return document.getElementById(tableId).rows[rowIndex].id; 
} 

는,이 기능을 사용하면 도움이해야합니다 :

function getIdOfRow(trElement) { 
    return trElement.id; 
} 

당신은 사용할 수 TABLEID 가정

답변

0

이 기능은 당신에게 도움이 될 테이블의 ID입니다 jQuery를 사용하면 작업을 단순화 할 수 있지만 이러한 기능은 jQuery를 원하지 않거나 사용할 수없는 사람들을 도울 수있는 기술에 구애받지 않습니다.

2
var myElementId; 

var option = { ... 
    onShow: applyrule, 
    onContextMenu: BeforeContextMenu 
}; 

function menuAction() { 
    alert(myElementId); 
} 

function applyrule(menu) { 
    myElementId = this.id 
} 
관련 문제