gpt4 book ai didi

jquery - 使用包含其他元素的 td 的 jQuery 替换 td 中的文本

转载 作者:技术小花猫 更新时间:2023-10-29 11:34:44 26 4
gpt4 key购买 nike

我的表格如下:

<table id='demoTable'>
<tr>
<td>8: Tap on APN and Enter <B>www</B>.
<INPUT id=h150000000000000109743 class=hid value="test value" type=hidden>
<INPUT id=h250000000000000109743 class=hid1 value="26,222,98,10,50000000000000109744,T,~25,221,99,10,,T,www" type="hidden">
</td>
</tr>
</table>

我只想更改文本 8: Tap on APN and Enter <B>www</B>.
不影响隐藏字段

我正在尝试 jQuery 但没有找到解决方案

function changeText() {
$("#demoTable td").each(function () {
for (var i = 0; i < $(this).children.length; i++) {
alert($(this).children(i).val());
}
// alert($(this).html());
// $(this).text("hello");
// alert($(this).html());
});
}

最佳答案

在 jquery 中使用文本节点是一项特别微妙的工作,大多数操作都完全跳过它们。

与其经历仔细避免错误节点的麻烦,不如将需要替换的任何内容包裹在 <span> 中。例如:

<td><span class="replaceme">8: Tap on APN and Enter <B>www</B>.</span></td>

然后:

$('.replaceme').html('Whatever <b>HTML</b> you want here.');

关于jquery - 使用包含其他元素的 td 的 jQuery 替换 td 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13816944/

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