1

我想将每个圆圈放在一个 div 中,这样我就可以使用 jquery 调整它的大小。我的代码如下:

<div id="DG_circles">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200" height="75">
<desc>Created with Raphaël</desc>
<defs>
<circle cx="39" cy="39.5" r="16" fill="#d57b19" stroke="none" style="stroke-width: 0;" stroke-width="0">
<image x="28.8" y="29.3" width="22.4" height="22.4" preserveAspectRatio="none" href="load?name=icon-hotel-chart">
<text x="39" y="17.5" text-anchor="middle" style="text-anchor: middle; font: bold 9px Arial,Verdana,Courier; stroke-width: 0;" font="10px "Arial"" stroke="none" fill="#333333" font-size="9px" font-family="Arial, Verdana, Courier" stroke-width="0" font-weight="bold">
<circle cx="91" cy="39.5" r="16" fill="#b1102b" stroke="none" style="stroke-width: 0;" stroke-width="0">
<image x="80.8" y="29.3" width="22.4" height="22.4" preserveAspectRatio="none" href="load?name=icon-card-chart">
<text x="91" y="17.5" text-anchor="middle" style="text-anchor: middle; font: bold 9px Arial,Verdana,Courier; stroke-width: 0;" font="10px "Arial"" stroke="none" fill="#333333" font-size="9px" font-family="Arial, Verdana, Courier" stroke-width="0" font-weight="bold">
<circle cx="143" cy="39.5" r="16" fill="#85bb3c" stroke="none" style="stroke-width: 0;" stroke-width="0">
<image x="132.8" y="29.3" width="22.4" height="22.4" preserveAspectRatio="none" href="load?name=icon-airplane-chart">
<text x="143" y="17.5" text-anchor="middle" style="text-anchor: middle; font: bold 9px Arial,Verdana,Courier; stroke-width: 0;" font="10px "Arial"" stroke="none" fill="#333333" font-size="9px" font-family="Arial, Verdana, Courier" stroke-width="0" font-weight="bold">
</svg>
</div>​


var $circle = $('#DG_circles').find("circle");

$circle.each(function(index, value){
    if(index == 0){
        $this.attr("r", "24");
    } else if(index == 1){
        $this.attr("r", "20");
    } else if(index == 2){
        $this.attr("r", "18");
    }
});

但它不会改变圆的“r”属性。请帮忙。谢谢你。

4

3 回答 3

3

为什么你甚至需要在each这里使用?

var $circle = $('#DG_circles').find("circle");
$circle.eq(0).attr("r", "24");
$circle.eq(1).attr("r", "20");
$circle.eq(2).attr("r", "18");
于 2012-06-27T12:39:29.620 回答
1

this是一个 dom 元素,而不是 jQuery。您必须将其转换为 jQuery 元素才能使用 jQuery 函数。

$(this).attr('r', 24);
于 2012-06-27T12:37:14.003 回答
1

尝试....

var circle = $('#DG_circles').find("circle");

circle.each(function(index, value){
    if(index == 0){
        $(this).attr("r", "24");
    } else if(index == 1){
        $(this).attr("r", "20");
    } else if(index == 2){
        $(this).attr("r", "18");
    }
});
于 2012-06-27T12:37:42.513 回答