我在一个后台 提交网页 然后我在网页里嵌了一段JS
但JS里 有this.className=this.className.replace(new RegExp(" iehover\\b"), "");
这个一句话 里面的\\ 我每次传 都会被替换成无
this.className=this.className.replace(new RegExp(" iehoverb"), "");
象这样大虾们 帮帮忙
但JS里 有this.className=this.className.replace(new RegExp(" iehover\\b"), "");
这个一句话 里面的\\ 我每次传 都会被替换成无
this.className=this.className.replace(new RegExp(" iehoverb"), "");
象这样大虾们 帮帮忙
stuHover = function() {
var cssRule;
var newSelector;
for (var i = 0; i < document.styleSheets.length; i++)
for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
{
cssRule = document.styleSheets[i].rules[x];
if (cssRule.selectorText.indexOf("LI:hover") != -1)
{
newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
}
}
var getElm = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<getElm.length; i++) {
getElm[i].onmouseover=function() {
this.className+=" iehover";
}
getElm[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" iehover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);
</SCRIPT>
原来的函数
我不会JAVASCRIPT 这个是网上拿来的
加红的字体 里的\\每次上传就被替换成空
怎么办
要不 换成别的写法也行 大侠办 帮帮忙吧
stuHover = function() {
var cssRule;
var newSelector;
for (var i = 0; i < document.styleSheets.length; i++)
for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
{
cssRule = document.styleSheets[i].rules[x];
if (cssRule.selectorText.indexOf("LI:hover") != -1)
{
newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
}
}
var getElm = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i <getElm.length; i++) {
getElm[i].onmouseover=function() {
this.className+=" iehover";
}
getElm[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" iehover/\/\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);
[code]
提交以后是这样的
this.className=this.className.replace(new RegExp(" iehover//b"), "");红色部分应该是\\
按7楼那样提交
提交以后的结果是这样的
this.className=this.className.replace(new RegExp(" iehover//b"), ""); 我想要的结果是
this.className=this.className.replace(new RegExp(" iehover\\b"), "");
this.className=this.className.replace(new RegExp(" iehover\/\/b"), "");
抱歉,是我写错了
this.className=this.className.replace(new RegExp(" iehover//b"), "");
this.className=this.className.replace(new RegExp(" iehover\\\\b"), "");
再不行我回家面壁去
这个的结果是 iehoverb 这样。。
郁闷
是不是我的哪个服务器商屏蔽了/这个符号啊
这个函数的意思是把当前classname去掉带"iehover\\b" 的字符串
我说整个函数
我JS不会 正在学 55555声明变量声明 FOR循环什么的就不用解释了
document.styleSheets[i].rules.length
cssRule = document.styleSheets[i].rules[x];
if (cssRule.selectorText.indexOf("LI:hover") != -1)
{
newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
var getElm = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i <getElm.length; i++) {
getElm[i].onmouseover=function() {
this.className+=" iehover";
}
getElm[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" iehover/\/\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", stuHover); 这些都不太理解
cssRule = document.styleSheets[i].rules[x]; //得到css表里的属性
if (cssRule.selectorText.indexOf("LI:hover") != -1) //如果属性包含L1:hover
{
newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover"); //将所有的LI:hover 替换成LI.iehover
document.styleSheets[i].addRule(newSelector , cssRule.style.cssText); //将新的css属性给css表
var getElm = document.getElementById("nav").getElementsByTagName("LI"); //取得id为nav这个节点下的所有LI节点
for (var i=0; i <getElm.length; i++) {
getElm[i].onmouseover=function() {
this.className+=" iehover"; //鼠标移动过去后在classname后加入class=iehover,目的是应用css
}
getElm[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" iehover/\/\b"), ""); //鼠标移走以后去掉这个属性
}
}
}
if (window.attachEvent) window.attachEvent("onload", stuHover); //等于window.onload=stuHover();
在公司没仔细看你的代码,费这么多事... 以为是转义问题.
其实
this.className=this.className.replace(new RegExp(" iehover\\b"), "");这个不用改,new RegExp(" iehover\\b")作用是匹配 以iehover结尾的字符串,replace(new RegExp(" iehover\\b"), "")就是将这个字符串替换为空.