JS在html中的字符串替换

html-css016

JS在html中的字符串替换,第1张

上面font标签加一个id,<font id="idFont" class="cfrq" style="font-size:12px">星期三,星期二</font>

这样在js中就可以

docunment.getElementById("idFont").innerText = "星期二,星期三"

这样就可以实现你想要的功能

如果你用JQuery的话也可以这样 $(".cfrq").text("星期二,星期三")

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>