【问题标题】:How to access <path> in a SVG document如何访问 SVG 文档中的 <path>
【发布时间】:2012-10-13 17:31:47
【问题描述】:

我正在创建几个可点击的地图,但未能成功尝试找到如何访问路径标签,以便我可以使地图中的所有不同县都可点击。 (SVG 文件非常复杂......这是结构,我无法更改它 - 它会为所有不同的状态自动生成):

<svg width="932.25827pt" height="569.25354pt" viewBox="0 0 932.25827 569.25354" enable-background="new 0 0 932.25827 569.25354"
version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<g id="Layers">
    <g id="Ohio_Counties">
        <clipPath id="SVG_CP_1">
            <path d="M0,569.25354L0,0L932.25827,0L932.25827,569.25354L0,569.25354z"/>
        </clipPath>
        <path clip-path="url(#SVG_CP_1)" fill="none" stroke="#4E4E4E" stroke-width="0.48003" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round" d="
    M374.18483,441.14215L375.38491,440.90214L375.62493,440.90214L376.58499,440.66213L376.82501,440.66213L377.54505,440.42212
            L378.02508,440.42212L378.2651,440.42212L378.74513,440.42212L379.46518,440.66213L381.14529,440.66213L381.38531,440.66213L
            381.62532,440.66213L382.10536,440.66213L382.8254,440.66213L384.50551,440.90214L384.74553,440.90214L386.18563,440.90214L386.42564,441.38217
            L386.42564,441.62218L386.42564,441.86219L386.66566,441.86219L386.90567,441.86219L386.90567,442.1022L386.90567,442.34221L"/>
       </path>   
    </g>
</g>

/* There are about 87 more paths in the file... this is just a part of one.*/

我正在使用 jquery.svg - 但在文档中没有找到解决方案。

这里是javascript:

function changeState(newState){
    nS = newState.replace(/\s/g, '');

    try {      
        var map = 'mapLayers/AEP'+nS+'Counties.svg';
            $("#contentCounties").empty();
            var currentCountyMap = $('#contentCounties').svg({loadURL: loc, onLoad: addClickEvents(this)});

        } catch(err){
           alert("the map " + currentCountyMap + " does not exist");
    }
}


function addClickEvents(){
    // this is where I want to put the code to 
    // add click events to the individual paths.
    // Whether it's running a loop or using a jquery selector
    // I'm fine with either.

    // This is, in theory, what I think I want - but alas, it is wrong:
    var svg=document.getElementByTagName("path");
    alert(svg);
}

【问题讨论】:

    标签: javascript jquery path svg tags


    【解决方案1】:

    看起来您刚刚将 s 排除在 getElementsByTagName 之外

    【讨论】:

      猜你喜欢
      • 2013-10-03
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多