您现在的位置是:首页 > 电脑技术查询 > web开发

一道JS面试题,求解解决办法

编辑:chaxungu时间:2022-10-02 23:15:24分类:web开发

一道JS面试题,求解
将下面的引号替换
HTML code<div class="outer" style="border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;">
替换结果:
HTML code<div class=<span class="red">"outer"</span> style=<span class="red">"border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;"</span>>

引号前是一种值,引号后是一种值。

------解决方案--------------------
捕获 替换
查阅js的正则API

------解决方案--------------------
JScript codevar str='<div class="outer" style="border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;"> ';alert(str.replace(/(\"[^"]*\")/g,"<span class=\"red\">$1</span>"));
------解决方案--------------------
楼上 可行

上一篇:崩溃了!该怎么解决

下一篇:JS