字符串替换工具
只能替换第一个查找到的字符,不能替换全部,如果要继续替换可以把下面的替换结果赋值到原字符串,然后点击提交
代码
<!DOCTYPE html>
<html>
<head>
<style>
span{
display:block;//将内联元素转换成块级元素
height:20px;
width:200px;
}
</style>
<script>
function p(s){
document.write(s);
document.write("<br>");
}
function replace(){
regtext=document.getElementById('regtext').value;
search=document.getElementById('search').value;
repla=document.getElementById('replace').value;
//var str=new RegExp(search,"p");
document.getElementById('result').value=regtext.replace(search,repla);
}
</script>
</head>
<body>
<span>字符串替换工具</span>
<span>原字符串:</span><textarea id="regtext"></textarea>
<span>查询:</span><input type="text" id="search">
<span>替换为:</span><input type="text" id="replace">
<span>替换结果:</span><textarea id="result"></textarea>
<br>
<input type="submit" onclick="replace()">
</body>
</html>

浙公网安备 33010602011771号