我有一个内联SVG的html页面。并且路径元素上有一个事件处理程序。 这在浏览器(Chrome / IE / FF)中非常有效,但是当我在JAVAFX8的webview中尝试这个时。 不会触发路径元素的click事件。
这是示例代码。 http://jsfiddle.net/YTWw9/4/
$('path').click(function(event){
$(event.target).attr('stroke', "yellow");
});
答案 0 :(得分:0)
我使用不同的方法使用SVG和XML与数据库链接,它发布在我的blogspot
http://mksugumaran.blogspot.in/2014/04/svg-scalable-vector-graphics-in-web-page.html
使用的源代码是
<html>
<head>
<title>Tamilnadu Rainfall data in GIS</title>
<style>
p.pos_fixed1
{
FONT: bold 14px Verdana, Arial, Helvetica, sans-serif;
COLOR: #000066;
position:fixed;
top:30px;
left:20px;
z-index=10;
}
p.pos_fixed2
{
FONT: bold 14px Verdana, Arial, Helvetica, sans-serif;
COLOR: #000066;
position:fixed;
top:45px;
left:20px;
z-index=10;
}
iframe.pos_fixed3
{
top:75px;
left:0px;
position:fixed;
width:250px;
height:300px;
}
</style>
<script language="javascript">
var aHexArray="0123456789ABCDEF";
var LLXC=75.0;
var LUYC=13.5833332538605;
var CS=0.00083333333333333;
var x1 = new Array();
var y1 = new Array();
var n1,ild;
var i,j;
var nx;
function fnRandomDec(){
var iMaxDec=256;
var iRandDec=parseInt((iMaxDec*Math.random())-1);
return iRandDec;
}
function fnReturnHex(iDecValue){
return aHexArray.charAt((iDecValue>>4)&0xf)+aHexArray.charAt(iDecValue&0xf);
}
function fnRandColor(){
return "#" + fnReturnHex(fnRandomDec()) + fnReturnHex(fnRandomDec()) + fnReturnHex(fnRandomDec());
}
function drawing(zx)
{
var txt1;
txt1=""
y=xmlDoc.getElementsByTagName("svg")[0].childNodes;
//document.write(y.length-1);
//document.write("<svg onclick=fnchange(); width='" + Math.round(6700/zx) + "' height='" + Math.round(6700/zx) + "'>");
txt1= txt1 + "<svg style=z-index:2; width='" + Math.round(6700/zx) + "' height='" + Math.round(6700/zx) + "' xmlns:xlink='http://www.w3.org/1999/xlink'>";
for (j=0;j<y.length;j++)
{
x=xmlDoc.getElementsByTagName("Polygon")[j].childNodes;
//document.write(x.length-1);
//document.write("<polygon points='");
name=x[0].childNodes[0].nodeValue;
txt1=txt1 + "<a xlink:title=" + name + " xlink:href='wdb4x.asp?dbname=tnrfs&2=xx'" + " target='xy1'>"
txt1= txt1 + "<polygon points='";
for (i=1;i<x.length;i++)
{
gxy=x[i].childNodes[0].nodeValue;
n1=gxy.indexOf(",");
x1[i]=gxy.substr(0,n1);
y1[i]=gxy.substr(n1+1);
txt1= txt1 +Math.round(x1[i]/zx)+','+Math.round(y1[i]/zx)+' '
}
txt1=txt1 +"' style='fill:" + fnRandColor() + ";stroke:black;stroke-width:1'></polygon></a>";
}
colr=fnRandColor();
y=xmlDoc1.getElementsByTagName("svg")[0].childNodes;
for (j=0;j<y.length;j++)
{
x=xmlDoc1.getElementsByTagName("point")[j].childNodes;
name=x[0].childNodes[0].nodeValue;
gxy=x[1].childNodes[0].nodeValue;
n1=gxy.indexOf(",");
xx1=gxy.substr(0,n1);
yy1=gxy.substr(n1+1);
str1=name + ':' + Math.abs(LUYC-yy1*CS) + ',' + Math.abs(LLXC+xx1*CS);
txt1=txt1 + "<a xlink:title=" + str1 + " xlink:href='wdb4x.asp?dbname=tnrfs&2=" + name + "' target='xy1'"+"'>";
txt1=txt1 + "<circle cx='" + Math.round(xx1/zx) +"' cy='" + Math.round(yy1/zx) + "' r='5' stroke='black' stroke-width='1' fill='"+ fnRandColor() +"'></circle></a>";
}
txt1=txt1 + "</svg>";
scr1.innerHTML=txt1;
}
function position3(xx1,yy1)
{
xy1.style.top=Math.round(yy1/zx);
xy1.style.left=Math.round(xx1/zx);
}
function fnchange()
{
nx=nx-1;
if(nx==0)nx=1;
drawing(nx);
}
function fnchange1()
{
nx=nx+1;
if(nx>10)nx=10;
drawing(nx);
}
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
function loadXMLString(txt)
{
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(txt);
}
return xmlDoc;
}
xmlDoc=loadXMLDoc("tnbasins.xml");
xmlDoc1=loadXMLDoc("tnrfl.xml");
</script>
</head>
<body>
<p class="pos_fixed1" onclick="fnchange1();">zoom_out</p>
<p class="pos_fixed2" onclick="fnchange();">zoom_in</p>
<iframe class="pos_fixed3" style=width:250;height:300;z-index:1; z-index=-1; name=xy1 border=none frameborder=none></iframe>
<table><tr><td id=scr1></td></tr></table>
<script language="javascript">
if (xmlDoc && xmlDoc1)
{
nx=10;
drawing(nx);
}
</SCRIPT>
</body>
</html>