2

I am using a chart from Raphael.js and I really have a very little experience with javascript and JQuery that's why I would like to ask you guys, so I'll go straight to the point.

I have some problems regarding the fill data. I simply wanted to get all the fill data (in this example there are two text tags so I wanted to get two fill="#ff0000" and fill="#00e0ff"

<text style="font: 20px "Arial"; opacity: 1; text-anchor: middle;" x="555.0919781452639" y="222.43750078648324" text-anchor="middle" font="10px "Arial"" stroke="none" fill="#ff0000" opacity="1" font-size="20px">
   <tspan dy="7.000000786483241">Ruby</tspan>
</text>

<text style="font: 20px "Arial"; opacity: 1; text-anchor: middle;" x="604.746975531892" y="434.94193863997384" text-anchor="middle" font="10px "Arial"" stroke="none" fill="#00e0ff" opacity="0" font-size="20px">
   <tspan dy="7.000532389973841">PHP</tspan>
</text>

anyway i created a jsfiddle account for it i really still don't have an idea can you guys help me out? http://jsfiddle.net/psyreaper3/rXXem/9/

4

4 回答 4

3

尝试将此代码放入您的回调函数中:

$('text').each(function(){
    alert($(this).attr('fill'));
});
于 2013-04-14T09:30:44.757 回答
1

一个看起来有点难看但功能强大的解决方案是:

$($('text')[0]).attr('fill');(这会给你第一个文本的填充属性)和
$($('text')[1]).attr('fill');(这会给你第二个)。

理想情况下,您会在这些元素上使用 id,以便您轻松获取特定的文本元素属性。

<text id="first" fill="blah"></text>然后你可以做$('#first').attr('fill');

于 2013-04-14T09:19:37.590 回答
0

您可以通过这种方式获得填充属性。

$('text').each(function(){
   alert($(this).prop('fill'));
})
于 2013-04-14T09:17:51.723 回答
0

更新小提琴

您可以通过以下方式获取填充属性:

$(this).attr('fill');

并可以通过使用更新它:

$(this).attr('fill','#ffee00');
于 2013-04-17T05:05:16.830 回答