svg 动态修改text文本 |
您所在的位置:网站首页 › svg修改文字 › svg 动态修改text文本 |
SVG Text的文本由于不是他的属性,因此不能采用setAttribute来更改。 下面说两种不同方式实现: 1、通过改变他的textContent 例如:svg内容如下,但是非常遗憾这种方法不适合IE6。Opera10是可以的
var text, textnode function init(){textnode = document.getElementById("text1")} function changeText(){text = textnode.textContenttextnode.textContent = "test"} function restoreText(){textnode.textContent = text} ]]>OMG
2、第二种方法创建一个新的TextSpan替换旧的经过在IE6下测试好用。其他的浏览器没有试过 例如:下面是主要函数 function changeDescriptionText(evt,siteNum){ var newDescriptionText = svgDocument.createTextNode("Click here to goto DeveloperWorks."); targetText.replaceChild(newDescriptionText,targetText.getFirstChild()); } |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |