如何使用D3来附加几行html代码
How to use D3 to append several html line of codes
我需要使用D3:添加所有这些代码
<fieldset style="width: 280px; margin-left: 45px; position: absolute;" >
<legend>Options</legend>
<d>Rotation: </d>
<select id="rotation" style="position: center;">
</select>
<d>Inclination: </d>
<select id="inclination" style="position: center;">
</select>
</fieldset>
我需要D3的原因是,我只想在某个任务完成后添加这段代码,并且只想在完成后填充两个Select
元素。
我该怎么做?非常感谢
您可以使用d3.html()
。
首先选择要放置控件的出口,然后使用html方法插入控件。
d3.select('#where-you-want-the-output').html('<fieldset style="width: 280px; margin-left: 45px; position: absolute;" ><legend>Options</legend><d>Rotation: </d> <select id="rotation" style="position: center;"></select> <d>Inclination: </d><select id="inclination" style="position: center;"></select></fieldset>');
如果您想在源代码中保留格式,可以使用'
生成多行字符串。
d3.select('body').html(
'<fieldset style="width: 280px; margin-left: 45px; position: absolute;" > '
<legend>Options</legend> '
<d>Rotation: </d> '
<select id="rotation" style="position: center;"> '
'
</select> '
<d>Inclination: </d> '
<select id="inclination" style="position: center;"> ]
'
</select> '
</fieldset>');
如果您为d3.html
提供一个参数,它将为该选择设置html,但如果您在没有参数的情况下调用它,它将返回已经存在的内容。所以,如果你有现有的内容,你可以把它拉成这样的字符串。。。
d3.select('#where-i-want-to-add-more-content').html(
d3.select('#where-i-want-to-add-more-content').html() + // get what's already there...
'<fieldset style="width: 280px; margin-left: 45px; position: absolute;" > '
<legend>Options</legend> '
<d>Rotation: </d> '
<select id="rotation" style="position: center;"> '
'
</select> '
<d>Inclination: </d> '
<select id="inclination" style="position: center;"> ]
'
</select> '
</fieldset>'
);
不过,在这一点上,它可能会变得有点混乱,您最好为消息提供一个特定的容器,您可以随时覆盖其内容。或者使用d3.append
以编程方式构建输出。
希望这能有所帮助。
相关文章:
- 如何删除多行HTML排列中的空白
- 在新行(html)中动态添加更多文本字段
- 用PHP/MMySQL和JavaScript填充几个HTML分区
- Sencha Touch使用pageSize配置只加载几行
- 用于匹配错误和关联几行的正则表达式
- 我可以'不要让这几行简单的代码正常工作,也不知道为什么
- 如果字段在几行空行之后包含前几个字符,则验证描述字段长度
- 在Javascript中处理多行HTML
- JMeter-正则表达式提取器-多行html
- 几个HTML文件上的页面特定JavaScript函数
- 如果用户单击表格行,则显示或隐藏表格行(HTML/JQuery)
- Javascript中的多行(HTML和JSP)
- 只对表的几行进行排序 - jquery/ javascript
- 用户未输入几行时的 JavaScript 计算(添加剩余的行值)
- 单击时添加几行,双击删除添加的行
- 数组中的字符串显示为未定义,尽管在几行之前成功.log控制台
- 无法跨越带有单引号或双引号的换行 html 文本
- 不太确定几行代码
- 获取存储在几个HTML元素中的数据
- 如何使用D3来附加几行html代码