两个文件放在同一目录
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
svg主文件
tt.svg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN" 
"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">

 

<svg width="600" height="400">
<script type="text/ecmascript">
<![CDATA[

getURL("yy.xml", fileLoaded);
function fileLoaded (data) {
 var msg = '';
 if(data.success) {
 var newMenuRoot=parseXML(data.content,contextMenu);
 contextMenu.replaceChild(newMenuRoot,contextMenu.getDocumentElement());  
 } 
}
var target;
function onmousedown(evt){
if(evt.button==2) target=evt.getTarget();
}
function showAlert(evt){
if(target!=null)
{
 alert(target.getAttribute("id"));
}
target=null;
}
]]> </script> 
<g onmousedown="onmousedown(evt)">
<rect >
Hello, SVGViewer!
</text>
</g>
</svg>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

定义右建菜单的xml文件
yy.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?xml version="1.0" encoding="UTF-8"?>
<menu > 缩小 </item>
<item id='Menu2.2' action='ViewSource'>浏览源代码</item>
</menu>
</defs>
<script>
<![CDATA[
var svgdoc = evt.getTarget().getOwnerDocument();
var newMenuRoot=parseXML(printNode(svgdoc.getElementById('menu1')),contextMenu);
contextMenu.replaceChild(newMenuRoot,contextMenu.firstChild);
function Toto()
{
alert('你点的是工作1')
}
function Titi(strParam)
{
alert('你点的是工作2,而且还传递了一个参数: ' + strParam)
}
]]>
</script>
</svg>

相关文章:

  • 2021-11-15
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-11-12
  • 2021-08-22
猜你喜欢
  • 2021-09-12
  • 2021-06-09
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2022-02-07
  • 2021-11-17
相关资源
相似解决方案