【发布时间】:2019-09-10 12:03:39
【问题描述】:
我在 SVG 中有矩形和线条以及一个复选框。我想以某种方式制作一个选中的复选框以显示内容以及何时选中,否则不会。例如:当检查“区域”的复选框时,将显示“区域矩形”,并为“河流”相同。
这似乎并不难,但我对 JavaScript 完全陌生,找不到让它工作的方法。
脚本将采用 HTML 格式,并且能够在 Web 浏览器上显示。一切都是可见的,但我无法让复选框起作用。
我尝试使用“onClick”构建函数并将颜色更改为“none”。
<html>
<head>
<title>Web Mapping using SVG</title>
<script>
</script>
<style>
</style>
</head>
<body>
<form>
<fieldset style="width:600px; height:600px">
<legend>Layers</legend>
<input type="checkbox" id="areaCbx" /><strong id="areaTXT">Area</strong><br>
<input type="checkbox" id="riverCbx" /><strong id="riverTXT">River</strong><br>
<hr />
<svg width="100%" height="100%">
<g id="AreaSVG" >
<rect x="0" y="0" width="100" height="200" />
<rect x="120" y="0" width="100" height="200" />
<rect x="280" y="0" width="100" height="200" />
<rect x="400" y="0" width="100" height="200" />
<rect x="0" y="260" width="100" height="200" />
<rect x="120" y="260" width="100" height="200" />
<rect x="240" y="260" width="100" height="200" />
<rect x="360" y="260" width="100" height="200" />
</g>
<g id="RiverSVG">
<line x1="0" y1="230" x2="500" y2="230" style="stroke:blue;stroke-width:6"/>
<line x1="250" y1="230" x2="250" y2="0" style="stroke:blue;stroke-width:6"/>
<line x1="0" y1="500" x2="500" y2="500" style="stroke:blue;stroke-width:6"/>
</g>
</svg>
</fieldset>
</form>
</body>
</html>
【问题讨论】:
-
问题不是很清楚,代码也不是很容易运行。你能解释更多关于功能的信息吗?也许可以粘贴一个stackblitz链接
-
您好,感谢您的回复。我已经发布了应该能够通过网络浏览器读取为 HTML 的完整代码。我想要的是让复选框确定是否显示矩形(AreaSVG)或线条(RiverSVG)。如果 id id="areaCbx" 的复选框被选中,它应该显示是矩形,否则不是。
-
这里有错别字
<<g id="AreaSVG" >
标签: javascript css svg