gpt4 book ai didi

javascript - 查询/JavaScript : Replace html content with html tag

转载 作者:行者123 更新时间:2023-11-30 12:53:27 25 4
gpt4 key购买 nike

我是一个 jquery 学习者,

我的 table

<table id="table">
<tr >
<th>column 1</th>
<th>Address</th>
<th>column 3</th>
</tr>
<tbody>
<tr>
<td>test data</td>
<td class="address">My compnay, \n New Hil \n
six singama \n India
</td>
<td>some data</td>
</tr>
<tr>
<td>test data</td>
<td class="address">New Branch, \n New Hil \n
six singama \n India
</td>
<td>some data</td>
</tr>
<tr>
<td>test data</td>
<td class="address">Some company, \n New arcade \n
six singama \n India
</td>
<td>some data</td>
</tr>
</tbody>

每一行的第二列都有一个包含\n字符的地址,我想替换\n<br>加载页面时的标记(当文档准备好时)

Jsfiddle here

 $( document ).ready(function() {
var columns = $('tr').find('td:eq(2 )')
});

最佳答案

尝试:

$(document).ready(function() {
$("tr:gt(0)").each(function(){
var t = $(this).find("td:eq(1)");
var tx = $(t).text();
tx = tx.replace(/\\n/g,'<br/>');
$(t).html(tx);
});
});

Fiddle here.

你也可以这样尝试:

$(document).ready(function() {
$("td:contains(\n)").each(function(){
var t = $(this).text();
t = t.replace(/\\n/g,'<br/>');
$(this).html(t);
});
});

Fiddle here.

关于javascript - 查询/JavaScript : Replace html content with html tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com