使用 createElementNS 创建的元素不显示 [英] Element created with createElementNS doesn't show
本文介绍了使用 createElementNS 创建的元素不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次单击按钮时,我都尝试使用 JavaScript 创建一个带有 标记的新
.当我在控制台萤火虫中看到结果时,它可以正常工作,但屏幕上没有任何显示.我想要的是每次单击按钮时图像
出现在最后一个之后.
I'm trying to create a new <img>
with the <svg>
tag with JavaScript every time I click on the button. When I see the result in the console firebug it works correctly, but nothing on screen displays.
What I want is for an image <svg>
to appear after the last one every time you click the button.
提前致谢.
var svgNS = "http://www.w3.org/2000/svg";
mybtn.addEventListener("click", createCircleSVG);
function createCircleSVG(){
var d = document.createElement('svg');
d.setAttribute('id','mySVG');
document.getElementById("svgContainer").appendChild(d);
createCircle();
}
function createCircle(){
var myCircle = document.createElementNS(svgNS,"circle"); //to create a circle."
myCircle.setAttributeNS(null,"id","mycircle" + opCounter++);
myCircle.setAttributeNS(null,"cx",25);
myCircle.setAttributeNS(null,"cy",25);
myCircle.setAttributeNS(null,"r",100);
myCircle.setAttributeNS(null,"fill","black");
myCircle.setAttributeNS(null,"stroke","blue");
document.getElementById("mySVG").appendChild(myCircle);
}
推荐答案
创建 SVG:
var svg = document.createElementNS(ns, 'svg');
第一个函数:
function createSVG() { ... }
第二个功能:
function createSVGCircle() { createSVG() ... }
或分开:
createSVG();
createSVGCircle();
这篇关于使用 createElementNS 创建的元素不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文