<!--<script type"text/javascript">
asdsd
</script>-->下边这个正则不管用字符串 = 字符串.replace(new RegExp("<!--(<script.*>[.\n\r]*<\/script>)-->", "ig"), "$1");
alert(字符串);正则高手帮忙看下,谢谢……
asdsd
</script>-->下边这个正则不管用字符串 = 字符串.replace(new RegExp("<!--(<script.*>[.\n\r]*<\/script>)-->", "ig"), "$1");
alert(字符串);正则高手帮忙看下,谢谢……
解决方案 »
- 帮忙看下代码
- mailto
- 在线求助,大家帮忙看下
- 浮动帧
- 如何实现 下载软件,先输入密码确定后,才可以下载
- ■■高分请教:JavaScript做前端页面操作执行效验等逻辑,但是安全问题如何保证,浏览器都可以自由下载JavaScript文件或代码啊■■
- 请问各位大佬能否通过script脚本来自动点击网页上的按钮?
- Netscape下无法在一个html文件内读其他xml文件,也无法引入其他html,如何解决?
- div左右滑动隐藏效果,
- 有没有前端大神 解释一下 jquery datatable function里面的 a, b, c, d 是怎么赋值的
- javascript调用WROD打印
- js 怎么让文字做 圆周运动
/*
* 首页通公共类 对话框组件
*
* 插件盒子:plugins
* 注册名称:dialog、对话框
*/ (function() {
//创建配置对象
var _cfg = {
"mdlhome" : document.documentElement.lastChild.lastChild.src.replace(new RegExp("(.*\/){0,}([^\.]+.*)", "ig"), "$1"),
"shade" : null,
"alone" : null,
"combo" : null
}; //创建盒子对象
var _bin = function(that, model) {
try {
return function(p) { //创建内置常量
var cfg = shouyetong.cfg["plugins_dialog"]; //创建内置方法
var fun = {
createShade : function() {
var d = cfg["shade"];
if(!d) {
d = that.createElement("DIV", {
style : (function() {
return "position:fixed; top:0px; left:0px; z-index:1000000000; overflow:hidden; width:100%; height:100%; margin:0px; border:none; padding:0px; background:#000000;" +
"opacity:.50; -moz-opacity:.50; filter:alpha(opacity=50);" +
"_position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop));";
})(),
onclick : function(event) {
that.cancelBubble(event || p.window.event);
},
ondblclick : function(event) {
that.cancelBubble(event || p.window.event);
},
onmousedown : function(event) {
that.cancelBubble(event || p.window.event);
},
onmouseup : function(event) {
that.cancelBubble(event || p.window.event);
}
}, null, p.window);
cfg["shade"] = d;
p.window.document.body.appendChild(d);
}
},
removeShade : function() {
var d = cfg["shade"];
if(d) {
cfg["shade"] = null;
p.window.document.body.removeChild(d);
}
},
configMdlly : function() {
var d = p.alone ? cfg["alone"] : cfg["combo"][p.index];
var m = (function() {
if(/<.*>/.test(model)) {
return model;
} else {
var f = that.createElement("IFRAME", {src : model.indexOf("@") < 0 ? cfg["mdlhome"] + model + "/model.htm" : "/" + model.substring(1) + "/model.htm", style : "display:none;"}, null, p.window);
that.attachEvent(f, {
load : function() {
m = f.contentWindow.document.body.innerHTML;
d.removeChild(f);
}
});
d.appendChild(f);
}
})();
var t1 = setInterval(function() {
if(m) {
window.clearInterval(t1);
for(var a in p) {
m = m.replace(new RegExp("{=" + a + "}|%7B=" + a + "%7D", "ig"), p[a]);
}
if(p.script) {
m = m.replace(new RegExp("<!--(<script.*>[.\n\r]*<\/script>)-->", "ig"), "$1");
}
d.innerHTML = m;
that.ergodicElement(d, function(e) {
e.action = function() {act(arguments)};
e.example = that;
});
}
}, 100);
var t2 = setInterval(function() {
if(d.innerHTML) {
window.clearInterval(t2);
var _a = that.getDocumentByScroll(p.window).x;
var _b = that.getDocumentByScroll(p.window).y;
var _c = that.getDocumentBySize(p.window).width;
var _d = that.getDocumentBySize(p.window).height;
var _w = d.offsetWidth;
var _h = d.offsetHeight;
d.style.left = (_a + (_c - _w) / 2) + "px";
d.style.top = (_b + (_d - _h) / 2) + "px";
d.focus();
that.createAnimate(d, 10, 10, {
"opacity" : function(f, d) {
return f * 10 / 100;
},
"-moz-opacity" : function(f, d) {
return f * 10 / 100;
},
"filter" : function(f, d) {
return "alpha(opacity=" + f * 10 + ")";
}
});
}
}, 100);
},
createMdlly : function() {
var d = that.createElement("DIV", {
style : (function() {
return "position:absolute; z-index:2000000000; overflow:hidden; width:auto; height:auto; margin:0px; border:none; padding:0px; background:none;" +
"opacity:.0; -moz-opacity:.0; filter:alpha(opacity=0);";
})(),
tabindex : (function() {
return "0";
})(),
onfocus : function(event) {
p.shade ? fun.createShade() : fun.removeShade();
p.append ? p.window.document.body.appendChild(d) : null;
},
onclick : function(event) {
that.cancelBubble(event || p.window.event);
},
ondblclick : function(event) {
that.cancelBubble(event || p.window.event);
},
onmousedown : function(event) {
that.cancelBubble(event || p.window.event);
},
onmouseup : function(event) {
that.cancelBubble(event || p.window.event);
}
}, null, p.window);
p.alone ? cfg["alone"] = d : (cfg["combo"] = cfg["combo"] || {}, cfg["combo"][p.index] = d);
p.window.document.body.appendChild(d);
},
removeMdlly : function() {
var d = cfg["alone"];
if(d) {
cfg["alone"] = null;
p.window.document.body.removeChild(d);
}
if(p.alone) {
d = cfg["combo"];
if(d) {
for(var i in d) {p.window.document.body.removeChild(d[i])}
cfg["combo"] = null;
}
}
}
}; //创建内置行为
var act = function(a) {
var d = p.alone ? cfg["alone"] : cfg["combo"][p.index]; /******************** FUNCTION ********************/
if(a[0] == "drag") {
that.action("drag", {
window : p.window,
event : a[1],
target : d
});
}
/******************** FUNCTION ********************/
/******************** FUNCTION ********************/
if(a[0] == "close") {
p.window.document.body.removeChild(d);
if(!p.alone) {
delete cfg["combo"][p.index];
for(var i in cfg["combo"]) {
d = cfg["combo"][i];
break;
}
} else {
cfg["alone"] = null;
}
if(!i) {
fun.removeShade();
return;
}
}
/******************** FUNCTION ********************/ d.focus();
}; //初始化
p.window = p.window || top;
p.index = p.index || (Math.random() * 1E18).toString(16).toUpperCase();
p.ibase = p.ibase || model.indexOf("@") < 0 ? cfg["mdlhome"] + model + "/" : "/" + model.substring(1) + "/";
p.shade = p.shade !== undefined ? p.shade : true;
p.alone = p.alone !== undefined ? p.alone : true;
p.script = p.script !== undefined ? p.script : true;
p.append = p.append !== undefined ? p.append : true;
fun.removeMdlly();
fun.createMdlly();
fun.configMdlly();
return function() {act(arguments)}; };
} catch(error) { }
}; //注册组件
shouyetong.cfg["plugins_dialog"] = _cfg;
shouyetong.bin.plugins["dialog"] = _bin;
shouyetong.bin.plugins["对话框"] = _bin;
})();
w</script>-->
替换成:<script type"text/javascript">
w</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body>
<script type="text/javascript">
var html = '<!--<script type\"text/javascript\"> \n asdsd \n <\/script>-->';
var reg = /<!--(<script[^>]*>[\s\S]*<\/script>)-->/gi;
alert(html);
alert(html.replace(reg,"$1"));
</script>
</body>
</html>
写在RegExp里要加\\new RegExp("<!--(<script[^>]*>[\\s\\S]*<\\/script>)-->", "gi")
(.|\n)
因为小数点不能匹配换行符,所以要取一个并集,而
[.\r\n]
中的小数点在字符组[]中,所以被转义了,匹配的就是小数点本身,所以[.\r\n]匹配的就是“.”、“\r”、“\n”这三个字符中的一个,达不到匹配任意字符的目的(.|\n)的效率不如字符组
[\s\S]、[\w\W]、[\d\D]
其中[\d\D]的性能高些,而[\s\S]的用法被用习惯了,所以更常见一些另外
var reg = /<!--(<script[^>]*>[\s\S]*<\/script>)-->/gi;
这里要写作
var reg = /<!--(<script[^>]*>[\s\S]*?<\/script>)-->/gi;
因为使用了/g模式,说明可能会出现多个匹配项需要进行替换,使用贪婪模式时,两个匹配项中间的内容整体会被替换,类似于以下结构
<!--<script type"text/javascript">
匹配项一
</script>-->
中间内容
<!--<script type"text/javascript">
匹配项二
</script>-->替换为$1的结果是<script type"text/javascript">
匹配项一
</script>-->
中间内容
<!--<script type"text/javascript">
匹配项二
</script>
scr = scr.replace(/<!--(<script.*>[\s\S]*?<\/script>)-->/gi, "$1");
alert(scr);