我试图在我的页面上获取一组 div 并替换其中的一些 html,但我只能得到第一个 DIV。我使用了 getElementsByName 并得到了相同的结果。我确信有一个简单的解决方案,但我找不到。这是我在 jsfiddle 上的代码 - http://jsfiddle.net/Gt4p2/
<html>
<head>
<script>
function repl() {
var x=document.getElementById("post-content").innerHTML;
var y=x.replace(/Description/g,"<b>Description</b><br/>");
for (var i=0; i<x.length; i++) {
document.getElementById('post-content').innerHTML=y;
}
}
onload = repl;
</script>
</head>
<body>
<div id="post-content">
<p>Description Power: 1W*3pcs LED color: RGB color deterioration, red, yellow, blue, green, white </p>
</div>
<div id="post-content">
<p>Description Power: 1W*3pcs LED color: RGB color deterioration, red, yellow, blue, green, white </p>
</div>
<div id="post-content">
<p>Description Power: 1W*3pcs LED color: RGB color deterioration, red, yellow, blue, green, white </p>
</div>
</body>
</html>