JS 怎么把 <span>1<span> 替换为:<td>1</td>谢谢!
2 回答
RISEBY
TA贡献1856条经验 获得超5个赞
<html>
<head>
<title>
</title>
</head>
<body>
<script type="text/javascript">
window.onload=function (){
var str="<span>1</span>";
var str_1=str.replace(/(<span>)(1)<\/span>/g,"<td>$2</td>");
alert(str_1);
}
</script>
</body>
不知道这样是不是你所描述的那样呢????
哔哔one
TA贡献1854条经验 获得超8个赞
var
oldStr =
"<span>1<span><span>1<span>"
;
//var newStr = oldStr.replace("<span>1<span>","<td>1</td>"); //替换第一个
var
newStr = oldStr.replace(eval(
"/<span>1<span>/g"
),
"<td>1</td>"
);
//替换所有
添加回答
举报
0/150
提交
取消