Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript在特定单词后添加一个分隔符_Javascript_Css - Fatal编程技术网

使用Javascript在特定单词后添加一个分隔符

使用Javascript在特定单词后添加一个分隔符,javascript,css,Javascript,Css,我在一个网站(内置WordPress)上工作,我有一个表格插件,我不能简单地使用br标记来分解单词或文本,甚至插入span,因为表格插件不允许HTML标记 我想要达到的是打破一些th文本 在特定情况下,我想这样拆分此文本: 安扎哈尔 齐默 净值- 沃恩弗勒什 Verkaufs-preis 瑞士法郎 我想知道如何用它来实现这一点 这里是表格th <th data-class="expand" class="wdtheader sort column-block sorting" style

我在一个网站(内置WordPress)上工作,我有一个表格插件,我不能简单地使用
br
标记来分解单词或文本,甚至插入
span
,因为表格插件不允许HTML标记

我想要达到的是打破一些
th
文本

在特定情况下,我想这样拆分此文本:

安扎哈尔
齐默

净值-
沃恩弗勒什

Verkaufs-
preis 瑞士法郎

我想知道如何用它来实现这一点

这里是表格
th

<th data-class="expand" class="wdtheader sort  column-block sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Haus: activate to sort column ascending">Haus</th>
<th class="wdtheader sort  column-wohnung sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Wohnung: activate to sort column ascending">Wohnung</th>
<th class="wdtheader sort  column-anzahlzimmer sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Anzahl Zimmer: activate to sort column ascending">Anzahl Zimmer</th>
<th class="wdtheader sort  column-etage sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Etage: activate to sort column ascending">Etage</th>
<th class="wdtheader sort  column-nettowohnflache sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Netto-wohnfläche: activate to sort column ascending">Netto-wohnfläche</th>
<th class="wdtheader sort  column-sitzplatz sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Aussenfläche: activate to sort column ascending">Aussenfläche</th>
<th class="wdtheader sort  column-verkaufspreischf sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Verkaufspreis CHF: activate to sort column ascending">Verkaufspreis CHF</th>
<th class="wdtheader sort  column-pdf sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="PDF: activate to sort column ascending">PDF</th>
<th class="wdtheader sort  column-anfrage sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Anfrage: activate to sort column ascending">Anfrage</th>
豪斯 沃农 安扎尔·齐默 埃塔格 内托·沃恩弗勒什 奥森弗勒什 维考夫斯普雷斯瑞士法郎 PDF 安弗拉格
这里是完整的表代码

我假设表插件为
标记或
thead
th
的有效父标记分配id

例如:

HTML:

<table id="table">

<th data-class="expand" class="wdtheader sort  column-block sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Haus: activate to sort column ascending">Haus</th>

<th class="wdtheader sort  column-anzahlzimmer sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Anzahl Zimmer: activate to sort column ascending">Anzahl Zimmer</th>

<th class="wdtheader sort  column-nettowohnflache sorting" style="" tabindex="0" aria-controls="table_1" rowspan="1" colspan="1" aria-label="Netto-wohnfläche: activate to sort column ascending">Netto-wohnfläche

</table>
var th = document.querySelectorAll('#table th');

th.forEach(function(t) {

  var text = t.textContent;

  var output = text.replace(/[ |-]/g, '<br>');

  console.log(output); // check your browser console for output.

  t.innerHTML = output;

});

豪斯
沃农
安扎尔·齐默
埃塔格
内托·沃恩弗勒什
奥森弗勒什
维考夫斯普雷斯瑞士法郎
PDF
安弗拉格
C
C16–0.1
3½
如
约99,0平方米
约16.5平方米+拉森弗勒什
570’000
C
C16–0.2
4½
如
约113.5平方米
约16.5平方米+拉森弗勒什
665’000
C
C16–1.1
4½
奥格
约113.5平方米
约15.5平方米
630’000
C
C16–1.2
4½
奥格
约113.5平方米
约15.5平方米
650’000
C
C16–2.1
3½
阿提卡
约88.5平方米
约35,0平方米
620’000
C
C18–0.1
3½
如
约99,0平方米
约16.5平方米+拉森弗勒什
590’000
C
C18–0.2
4½
如
约114,0平方米
约16.5平方米+拉森弗勒什
645’000
C
C18–1.1
4½
奥格
约112.5平方米
约15.5平方米
650’000
C
C18–1.2
4½
奥格
约113.5平方米
约16,0平方米
630’000
C
C18–2.1
3½
阿提卡
约88.5平方米
约35,0平方米
620’000
C
C18–2.2
4½
阿提卡
约132,0平方米
约71,0平方米
845’000
安扎尔·齐默
埃塔格