js替换指定内容正则表达式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js替换指定内容正则表达式</title>
<script type="text/javascript教程">
function replacebyid(str, id, value)
{
var reg = new RegExp("\b" + id + "=\d+");
str = str.replace(reg, id + "=" + value);
return str;
}
var test = "";
document.write(replacebyid(test, 1, 909) + "<br />");
document.write(replacebyid(test, 2, 88) + "<br />");
</script>
</head>
<body>
<div id="adic">
1=100&2=22&3=77&5=93&6=321&7=0&
js正则替换文件指定内容
</div>
</body>
</html>
时间: 2024-10-24 10:36:20