简体   繁体   English

使用d3在表格单元格中插入文本

[英]Insert text in a table cell with d3

How can I add text to a cell using d3? 如何使用d3向单元格添加文本?

I have a function with the code that needs to be added and I'm calling this in the body of the html page. 我有一个需要添加代码的函数,我在html页面的主体中调用此函数。 I have the following code as an example but it doesn't seem to be working. 我以以下代码为例,但似乎无法正常工作。

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href ="styles.css">
<script type="text/javascript" src="http://d3js.org/d3.v4.min.js"></script>
<script type="text/javascript">
    function t1(){
    d3.select("td#target").text("14");
    }
</script>
</head>
<body onload="t1()">
  <table>
      <tr>
        <th>Name</th>
        <th>Surname</th> 
        <th>Age</th>
      </tr>
      <tr>
        <td>Tom</td>
        <td>Smith</td> 
        <td is="target"> </td>
      </tr>
  </table>
</body>
</html>

Any ideas on how to make this work. 关于如何使这项工作的任何想法。

It is a small mistake.. 这是一个小错误。

change <td is="target"> into <td id="target"> <td is="target">更改为<td id="target">

I found the solution. 我找到了解决方案。 I figured out I had just a typo 我发现我有错字

<td is="target"> </td>

Should be 应该

<td id="target"> </td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM