2013-05-08 56 views
2

我想變更的SVG的這個文本部分:通過jquery的在SVG改變文本(文本是一個動態值 - 溫度)

<text id="VL_temp" xml:space="preserve" style="font-size:40px;font-style:normal;font-weight:normal;line-height:100%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr" x="432.24234" y="110" sodipodi:linespacing="100%">**--**</text> 

我想顯示溫度,附帶從KNX-安裝 我試着用下面的代碼,但沒有任何反應:

<script> 
<![CDATA[ 
var thisGA = '14/0/4'; 
var thisTransform = 'DPT:9.001'; 
visu = new CometVisu('/cgi-bin/'); 
visu.update = function (json) 
{ 
    var temp = Transform[thisTransform].decode(json[thisGA]); 
    $('#VL_temp', svg.root()).text('temp'); 
} 
$(window).unload(function() { 
    visu.stop(); 
}); 
visu.user = 'demo_user'; 
visu.subscribe([thisGA]); 
]]> 

用什麼開頭的行$(「#VL_temp」的其餘部分的問題?代碼似乎是確定的,因爲這部分與jQuery另一個SVG工作(svn-link to the svg

回答

5

<text>標籤我SVG應包含<tspan>標籤和文本內容應該由<tspan>標籤,就像這樣:

<text id="VL_temp" xml:space="preserve" style="" x="432.24234" y="110" sodipodi:linespacing="100%"><tspan>**--**</tspan></text> 

代碼需要被更新:

$('#VL_temp tspan', svg.root()).text('temp'); 
-1

我可以只選擇這樣的ID來改變它:

$('#VL_temp').text("replaced");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<svg> 
 
<text id="VL_temp" xml:space="preserve" style="font-size:40px;font-style:normal;font-weight:normal;line-height:100%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr" dy="1em" sodipodi:linespacing="100%">hello world</text> 
 
</svg>