【问题标题】:Adding span class for variable为变量添加跨度类
【发布时间】:2018-09-11 08:34:55
【问题描述】:

我正在查看一位同事的 JS 文件,该同事已离开我的工作场所,因此无法访问它们。

//populate the inheritance table but remove all rows first
$("#reportBeneficiariesTable tbody").html("");

$(".saved-beneficiary").each(function() {
        $( "#reportBeneficiariesTable tbody" ).append( "<tr style=\"height:40px\">" + 
        "<td>"+$(this).find(".name").html()+"</td>" +
        "<td>"+$(this).find(".relation").html()+"</td>" +
        "<td>"+$(this).find(".inheritanceVal").html()+"</td>" +
        "<td>"+$(this).find(".taxableInheritance").html()+"</td>" +
        "<td>€"+$(this).find(".taxLiability").html()+"</td>");

我正在尝试将 .name 的变量用作跨度类以将输入名称进一步引入页面下方?我认为这可以通过以下方式实现:

 $('.name-1').html(name);

但似乎不起作用?任何帮助将不胜感激

【问题讨论】:

  • 你到底想要什么?你能描述一下想要的输出吗?
  • 我希望能够获取在 " "+$(this).find(".name").html()+" 中输入的值”。这是一个名称,并在页面中的一个句子中输出它,例如 是我的名字。

标签: javascript html


【解决方案1】:

您也可以使用 CSS。如果允许使用 CSS,则可以将表格的行转换为 flexbox 并更改内部 &lt;td&gt;s 的顺序,例如:

table *{border:1px solid #d9d9d9;padding:.5em;}

table{display:block;}
table tr{display:flex;}
.name{order:1}
<table>
<tr>
<td class="name">name</td>
<td class="relation">relation</td>
<td class="inheritanceVal">inheritanceVal</td>
<td class="taxableInheritance">taxableInheritance</td>
<td class="taxLiability">taxLiability</td>
</tr>
</table>

【讨论】:

  • 我不会太有信心替换以前的 javascript,以防它影响其他地方。
  • 我怎样才能在别处调用名称的跨度。我已将表格替换为您的示例,并获得了我之前在表格中输入的输出,但是当我尝试 它不起作用?
  • 我不太确定我是否理解你。你没有&lt;span class=name"&gt; 你有&lt;td class="name"&gt;。您可以通过它的类或它在标记中的位置来调用它。请添加您想要做的示例
  • 如果我有上面那个表。我想用下面的一句话说。我的名字是约翰,我的亲戚是孩子。 'John' 和 'Child' 将从表中取出。如果这有意义
  • conye9980 这是一个完全不同的问题。如果您喜欢我之前的回答,请接受并提出新问题
猜你喜欢
  • 2017-09-10
  • 2019-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多