2 回答
TA贡献1856条经验 获得超17个赞
对于此代码,您不需要任何id或class
const paragraphs = document.querySelectorAll('p')
paragraphs.forEach((paragraph) => {
if (paragraph.innerText == 'http://localhost:1111/') {
return (paragraph.innerHTML = `
<img src='https://www.stockgumshoe.com/wp-content/uploads/2014/06/test.jpg' />
`)
}
})
TA贡献1818条经验 获得超7个赞
而不是这个:
<script>
var str = document.getElementById("test").innerHTML;
var res = str.replace("http://localhost:1111", lement.innerHTML = "<img
src='https://www.stockgumshoe.com/wp-content/uploads/2014/06/test.jpg");
document.getElementById("demo").innerHTML = res;
</script>
尝试这个:
<script>
document.getElementById("test").innerHTML = `<img
src="https://www.stockgumshoe.com/wp-content/uploads/2014/06/test.jpg" />`;
</script>
添加回答
举报