我的网页上有一个 svg。右键单击元素时应显示一个上下文菜单,其中包含从数据库中获取的数据。元素的编写方式是右键点击事件触发页面上的一个js函数。我需要从 java 脚本调用上下文菜单。有人可以帮我解决这个问题。我已经被这个问题困扰了将近 3 天。元素:
<rect/><text>L</text></g><g id="118" onmousedown="RightClickExecute(event,118)">
java脚本:
function RightClickExecute(event, id) {
if (event.button == 2) {document.getElementById("myForm:selectedEntityid").value = id;
document.getElementById("myForm:selectedObjectType").value = 'Entity';
document.getElementById("myForm:RightAction").click();
}
}
function showContextMenu(){
document.getElementById("myForm:contextMenuItemId").click();
}
XHTML:
<p:contextMenu id="contextMenuId" for="svgContainerPanel"
widgetVar="contextMenuVar" rendered="#{myBean.objectType=='Entity' ? true : false}">
<p:menuitem id="contextMenuItemId" ></p:menuitem>
</p:contextMenu>
<p:contextMenu event="click" id="contextMenu2Id" for="contextMenuId"
widgetVar="contextMenu2Var" model="#{my.model}" >
</p:contextMenu>
<p:commandButton id="RightAction" style="visibility:hidden"
action="#{myBean.populateMenu}" ajax="true"
type="submit" oncomplete="showContextMenu()"
update="contextMenuId,contextMenu2Id">
</p:commandButton>
<h:inputHidden id="selectedEntityid"
value="#{myBean.selectedEntityId}">
</h:inputHidden>
<h:inputHidden id="selectedObjectType"
value="#{myBean.objectType}">
</h:inputHidden>