gpt4 book ai didi

javascript - Jquery 替换 html 中的文本

转载 作者:太空宇宙 更新时间:2023-11-04 14:23:26 25 4
gpt4 key购买 nike

有没有比以下更优雅的方式替换 html 元素内的文本:

$el = $("#myDiv");
$el.html( $el.html().replace("something", "something new") );

最佳答案

$('#myDiv').html(function(index, oldhtml) {
return oldhtml.replace('something', 'something new');
});

关于javascript - Jquery 替换 html 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6212250/

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