js如何替换html内的字符串

html-css014

js如何替换html内的字符串,第1张

document.getElementById("你想修改的标签的ID").innerHTML

这是换里面的HTML代码

document.getElementById("你想修改的标签的ID").text

可以换里面的text

document.getElementById("你想修改的标签的ID").value

可以换里面的值

刚写的完整代码:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

</head>

<script>

window.onload = function(){

document.getElementById("anqu").innerHTML = document.getElementById("anqu").innerHTML.replace(/\|/g,"/")

}

</script>

<body>

<ul id="anqu">

<li>第一类|第二类|第三类</li>

</ul>

</body>

</html>