An example to generate a svg

SVG file:
empty.svg
Just an empty one.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect biztype="background" fill="#000000" height="100%" id="background" stroke="#000000" stroke-width="1" width="100%" x="0" y="0" />
<g id="Text">
<text fill="#ffffff" font-family="SimSun" font-size="13" x="10" y="20" >列表</text>
</g>
<g id="root">
</g>
</svg>

----------------------------------------------------------
HTML file:

<html>
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<title>SVG</title>
<script language="javascript">
function init(){
var svgNS="http://www.w3.org/2000/svg";
var xlinkNS="http://www.w3.org/1999/xlink";
var totalRows = 20;
var svgDocument = document.getElementById("devsvg").getSVGDocument();
document.getElementById("devsvg").height = 90 + totalRows * 50;
var newRoot = svgDocument.getElementById("root");
for (var i=0;i<=totalRows;i++) {
var g=svgDocument.createElementNS(svgNS,'g');
var img=svgDocument.createElementNS(svgNS,'image');
img.setAttribute("height", "40");
img.setAttribute("width", "40");
img.setAttribute("x", "30");
img.setAttribute("y", 40 + i * 50);
img.setAttributeNS(xlinkNS,"href","I.png");
g.appendChild(img);
var txt=svgDocument.createElementNS(svgNS,'text');
var tspan=svgDocument.createElementNS(svgNS,'tspan');
tspan.setAttributeNS(null, "id", i);
tspan.setAttribute("x", "90");
tspan.setAttribute("y", 65 + i * 50);
tspan.setAttribute("style", "font-family: Arial, sans-serif; font-size:14; fill:#990066; stroke:none;");
//tspan.addEventListener("click", submit, false);
tspan.setAttribute("onclick", "txtClick('"+i+"')");
tspan.setAttribute("cursor", "pointer");
var tnode = svgDocument.createTextNode(i);
tspan.appendChild(tnode);
txt.appendChild(tspan);
g.appendChild(txt);
newRoot.appendChild(g);
}
}
function txtClick(id){
alert(id);
// sendRequest("/someAction.do?Id="+id,"POST");
}
</script>
</head>

<body onload="init()">
<embed id="devsvg" pluginspage="http://www.adobe.com/svg/viewer/install/" align="top" src="empty.svg" width="200" type="image/svg+xml"/>
<hr>
Also, the width can be modified in init() as 'height' do. <br>
And I put a 40*40 I.png in the same folder. <br>
Test passed in IE and FF.
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值