javascript - jQuery 到 Vanilla JS,删除
问题描述
我想将这段 jQuery 转换为 Vanilla JS,但我没有找到任何功能可以做到这一点
$('p').html(function(i, html) {
return html.replace(/ /g, '')
})
解决方案
您可以使用该document.querySelectorAll
方法选择所有p
标签。
document.querySelectorAll("p").forEach(function(el) {
var html = el.innerHTML
html = html.replace(/ /g, '')
el.innerHTML = html
})
推荐阅读
- git - 无法从本地机器中的特定提交 ID 中提取相同的文件?
- mobile - hybird 移动应用程序的开发
- javascript - OL5 的 ScaleLine 不适用于 EPSG:25832
- nativescript - Nativescript chart how to show bar graph with negative values
- batch-file - 指向bat文件中的文件
- angular - 如何在 Angular 或 Ionic 中创建浮动水平滚动条
- typescript - Rxjs Subject#next 是否异步?
- c# - 使用实体框架在 foreach 中分配对象非常慢
- python - NAN 损失张量流
- asp.net - 使用 MyBase 调用私有方法