有难度的正则匹配 类似于语法高亮 你得整个惰性匹配 表达式 :("<s><sadas>asd<aaaaa><sadas>asdf<aaaaa></s>").match(/>([^<>]+?)</g); 结果: [">asd<", ">asdf<"] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 只是0楼的需求的话..<div id="status"></div><script type="text/javascript">window.onload = function () { var sStr = "<html version=\"1.0\" onclick=\"none\">这个是\"正文\"内容这个是\"这里需要用红色\"内容<!--这个是\"这个是测试的\"注释-->"; var pattern = /<(?:"[^"]*"|'[^']*'|[^"'>])*>|("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/ig; document.getElementById('status').innerHTML = sStr.replace(pattern, function (lastMatch, $1) { return !$1 ? lastMatch : $1.replace(/^(.)(.*).$/, function (lastMatch, $1, $2) { return $1 + '<span style="color:#F00;">' + ($2 || '') + '<\/span>' + $1; }); });}</script> 看看这个http://www.softpure.com/html/show_details/37.htm 不是需要5楼的效果,而是要实现仅仅把 <> 标签以外的""双引号内容用红色标注,其他保留3楼的接近了~~~呵呵~~谢谢各位~~~ - -,说清楚嘛.<div id="status1"></div><hr /><div id="status2"></div><script type="text/javascript">window.onload = function () { var sStr = "<html version=\"1.0\" onclick=\"none\">这个是\"正文\"内容这个是\"这里需要用红色\"内容<!--这个是\"这个是测试的\"注释-->"; var pattern = /<(?:"[^"]*"|'[^']*'|[^"'>])*>|(.)/ig; var a = []; document.getElementById('status2').appendChild(document.createTextNode( document.getElementById('status1').innerHTML = sStr.replace(pattern, function (lastMatch, $1) { if (!$1) { return ( a.length > 0 ? '<span style="color:#F00;">' + a.splice(0, a.length).join('') + '<\/span>' : '' ) + lastMatch; } else { a[a.length] = $1; return ''; } }) ) );};</script> 【分享】纯 JS 编写的贪吃蛇 PHP怎么播放视频文件 关于表格的一个貌似高难度问题 自定义提示框 ie6 与 ie7 的兼容性问题 百渡查询url后缀如何解码? Javascript测试题 大家看看呀 救急!!!·如何屏蔽浏览器右上角"关闭"键? validate 里有没有requireone的方法啊?就是两个输入框至少要输入一个 如果js中表单中字段的名称是由已知的变量构成,各位一般用什么方法得到字段? 请问:能否加密Javascript的函数文件? 怎么获取今天加n天那天的日期 高手请教:javascript导出excel如何不将隐藏列导出
<div id="status"></div>
<script type="text/javascript">
window.onload = function () {
var sStr = "<html version=\"1.0\" onclick=\"none\">这个是\"正文\"内容这个是\"这里需要用红色\"内容<!--这个是\"这个是测试的\"注释-->";
var pattern = /<(?:"[^"]*"|'[^']*'|[^"'>])*>|("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/ig;
document.getElementById('status').innerHTML =
sStr.replace(pattern, function (lastMatch, $1) {
return !$1 ? lastMatch : $1.replace(/^(.)(.*).$/, function (lastMatch, $1, $2) {
return $1 + '<span style="color:#F00;">' + ($2 || '') + '<\/span>' + $1;
});
});
}
</script>
仅仅把 <> 标签以外的""双引号内容用红色标注,其他保留3楼的接近了~~~呵呵~~谢谢各位~~~
<hr />
<div id="status2"></div>
<script type="text/javascript">
window.onload = function () {
var sStr = "<html version=\"1.0\" onclick=\"none\">这个是\"正文\"内容这个是\"这里需要用红色\"内容<!--这个是\"这个是测试的\"注释-->";
var pattern = /<(?:"[^"]*"|'[^']*'|[^"'>])*>|(.)/ig;
var a = [];
document.getElementById('status2').appendChild(document.createTextNode(
document.getElementById('status1').innerHTML =
sStr.replace(pattern, function (lastMatch, $1) {
if (!$1) {
return (
a.length > 0 ? '<span style="color:#F00;">' + a.splice(0, a.length).join('') + '<\/span>' : ''
) + lastMatch;
} else {
a[a.length] = $1;
return '';
}
})
)
);
};
</script>