希望能够利用javascript解析html字串,判断所有的<img>元素,如果结尾有加上/>,就像是<img />的话,就删除。
假设现在有一组字串:
<h1>h1</h1>
<img id="a" src="https://placehold.it/200x200" alt="" />
<h2>h2</h2>
<img id="b" src="https://placehold.it/200x200" alt="">
希望能够改为
<h1>h1</h1>
<img id="a" src="https://placehold.it/200x200" alt="">
<h2>h2</h2>
<img id="b" src="https://placehold.it/200x200" alt="">
我尝试使用jquery做判断,发现读入jquery时,似乎好像已经被标准化了,无法从jquery对象中判断原本的img tag 的html。
html
<img id="a" src="https://placehold.it/200x200" alt="" />
<img id="b" src="https://placehold.it/200x200" alt="">
javascript
console.log($("#a"));
console.log($("#b"));
两个打印出来的元素是一模一样的。
在python中的beautifulSoup和tag中,有个接口叫做isSelfClosing正是我需要的,请问这个在javascript有类似的库和接口吗?我找了jquery和cheerio的文档都没找到
相关分类