首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-03-28 
一道JS面试题,求解将下面的引号替换HTML codediv classouter styleborder:#ff0000 2px dotted heig

一道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 code
var 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>"));
[解决办法]
楼上 可行

热点排行