[英]How cna I a add comma between words in a td if there is more than one word
Long backstory on this, and this seems to be the simplest solution.很长的背景故事,这似乎是最简单的解决方案。 I have a table that will populate with user id's from a database.
我有一个表,它将使用数据库中的用户 ID 填充。 I need to figure out a way to add a comma between id's if there is more than one.
如果有多个,我需要想办法在 id 之间添加逗号。 The td id is
username
. td id 是
username
。
I'm not sure where to really start.我不确定从哪里真正开始。 I would need to index it and see if the html is > 1. And if so, add a comma between each word.
我需要索引它并查看 html 是否 > 1。如果是,请在每个单词之间添加一个逗号。 Please help.
请帮忙。 This is a poc forum and it doesn't suit me to add/use jQuery, so I need to do it in vanilla JavaScript.
这是一个 poc 论坛,它不适合我添加/使用 jQuery,所以我需要在原版 JavaScript 中进行。
Here is the code that pulls it from the database:这是从数据库中提取它的代码:
if ($this->post['post_thanks_amount'] > 0 && $this->thread['isdeleted'] == 0)
{
$this->post['post_thanks_bit'] = fetch_thanks_bit($this->thread['forumid'], $thanks);
$this->post['post_thanks_user'] = $post_thanks_user;
$this->post['post_thanks_amount_formatted'] = vb_number_format($this->post['post_thanks_amount']);
$post_thanks_box = fetch_post_thanks_template($this->post);
}
And the output with one user is this:一个用户的 output 是这样的:
<tr valign="top">
<td style="background:#E8E8E8;" colspan="2" class="alt1">
<div>
<a rel="nofollow" href="member.php?u=20420">ninja1</a>
<a rel="nofollow" href="member.php?u=26154">testuser</a>
</div>
</td>
</tr>
so after each <a...>
if there is more than one, add a comma.所以在每个
<a...>
之后,如果有多个,请添加一个逗号。
If ids is an array, then just use join
:如果 ids 是一个数组,那么只需使用
join
:
ids = [1, 2, 3, 4];
val = ids.join(', ');
// val is now "1, 2, 3, 4"
split()
automatically puts comma between words, if that's what you're looking for. split()
自动在单词之间放置逗号,如果那是你要找的。
var words = 'a b c d';
document.write(words.split(' '));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.