SVG <tref>元素用于引用由該 <defs> 元素定義的文本。這樣,您可以在SVG圖像中多次顯示相同的文本,而不必多次包含 <text>元素。
這是一個示例:
<svg width="100%" height="100%" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <text id="ReferencedText"> 引用字符數(shù)據(jù) (cainiaoplus.com) </text> </defs> <text x="100" y="100" font-size="45" > 內聯(lián)字符數(shù)據(jù) (cainiaoplus.com) </text> <text x="100" y="200" font-size="45" fill="red" > <tref xlink:href="#ReferencedText"/> </text> <!-- 使用“rect”元素顯示畫布的輪廓 --> <rect x="1" y="1" width="598" height="198" fill="none" stroke-width="2" /></svg>測試看看?/?
運行后圖像效果:
注意<text>元素(在元素內部<defs>)如何具有 id屬性。此id屬性值是從元素的xlink:href 屬性引用的<tref>。