JS在html中的字符串替换

html-css011

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

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

这样在js中就可以

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

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

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

假设你哪些要替换的代码在一个div里面,这个div的

id为myid,下面这样写:

var

myreplace=document.getElementById('myid').innerHTML

var

myresult=myreplace.replace(/等待替换的内容/ig,“想要替换的内容”)

document.getElementById('myid').innerHTML=myresult

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

这是换里面的HTML代码

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

可以换里面的text

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

可以换里面的值