2015-04-14 47 views
2

如何使每个元素的svg图像嵌入HTML文件中(比如用某种类的圆等)一个活动链接? 我需要一个代表一些元素的svg图像,它们应该是可点击的链接。如何使SVG元素成为链接?

这是SVG图像的片段:

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
    width="612px" height="792px" viewBox="0 0 612 792" enable-background="new 0 0 612 792" xml:space="preserve"> 
<a href="http://google.com" ><rect x="-124.203" y="112.232" fill="#E88324" stroke="#000000" stroke-miterlimit="10" width="175.362" height="226.087"/> </a> 

我做了第二次DIV:

<div class="displayer" style=" width:100%; height: 100%;"> 
</div> 

并试图做到这一点使用jQuery:

$(document).ready(function() { 
    $("a").click(function() { 
     // $("body").hide(); 
     $(".displayer").load("http://google.com"); 
}); 
    }); 

但它不”没有道理,你会怎么做?

+0

你并不需要声明的HTML里面的SVG所有的命名空间。 – Shikkediel

回答

2

试一试,试验fiddle

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
width="612px" height="792px" viewBox="0 0 612 792" 
enable-background="new 0 0 612 792" xml:space="preserve"> 
    <a xlink:href="http://google.com"> 
     <rect x="-124.203" y="112.232" fill="#E88324" 
     stroke="#000000" stroke-miterlimit="10" 
     width="175.362" height="226.087"/> </a> 
</svg> 

你只是忘记<a>xlink:hrefsvg