文本不会出现在DOM对象中? [英] Text doesn't appear in DOM object?
本文介绍了文本不会出现在DOM对象中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在javascript中创建一个对象并将文本附加到它。我可以将文本附加到svg中,但是当我尝试将其附加到一个圈子中时,它不会出现。
I'm trying to create an object in javascript and append text to it. I can append text to the svg just fine but when i try to append it to a circle for example, it doesn't appear.
这是我的代码看起来像:
This is what my code looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>D3 Tutorial</title>
<script src="http://d3js.org/d3.v3.min.js"> </script>
</head>
<body>
<script>
var canvas = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500);
var circle = canvas.append("circle")
.attr("cx", 400)
.attr("cy", 350)
.attr("r", 25);
canvas.append("text")
.attr("fill", "red")
.attr("y", 50)
.text("hello");
circle.append("text")
.attr("fill", "red")
.attr("y", 50)
.text("hello");
</script>
</body>
</html>
这是它的出现:
This is how it appears:
推荐答案
SVG必须遵循一定的结构。将文本
元素追加到圆圈
(或 rect
或类似)无效,因此不会显示。
SVGs have to follow a certain structure. Appending a text
element to a circle
(or rect
or similar) isn't valid so it won't be shown.
这篇关于文本不会出现在DOM对象中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文