我在一个后台 提交网页  然后我在网页里嵌了一段JS
但JS里 有this.className=this.className.replace(new RegExp(" iehover\\b"), "");
这个一句话  里面的\\  我每次传  都会被替换成无
this.className=this.className.replace(new RegExp(" iehoverb"), ""); 
象这样大虾们 帮帮忙

解决方案 »

  1.   

    this.className=this.className.replace(/ iehover\b/, ""); 
      

  2.   

    <SCRIPT type=text/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); 
    </SCRIPT>
    原来的函数
    我不会JAVASCRIPT 这个是网上拿来的 
    加红的字体 里的\\每次上传就被替换成空
    怎么办 
    要不 换成别的写法也行 大侠办 帮帮忙吧
      

  3.   

    [code=JScript]
    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]
      

  4.   

    楼上的方法不行 
    提交以后是这样的
    this.className=this.className.replace(new RegExp(" iehover//b"), "");红色部分应该是\\
      

  5.   

    重说便7楼的方法不行 
    按7楼那样提交 
    提交以后的结果是这样的 
    this.className=this.className.replace(new RegExp(" iehover//b"), ""); 我想要的结果是
    this.className=this.className.replace(new RegExp(" iehover\\b"), ""); 
      

  6.   

    是:
    this.className=this.className.replace(new RegExp(" iehover\/\/b"), ""); 
    抱歉,是我写错了
      

  7.   

    一样  结果都是
    this.className=this.className.replace(new RegExp(" iehover//b"), ""); 
      

  8.   

    晕了,左右有点晕
    this.className=this.className.replace(new RegExp(" iehover\\\\b"), "");
    再不行我回家面壁去
      

  9.   

    this.className=this.className.replace(new RegExp(" iehover\\\\b"), ""); 
    这个的结果是 iehoverb 这样。。
    郁闷 
    是不是我的哪个服务器商屏蔽了/这个符号啊
      

  10.   

    算了 我是服了大侠们 谁帮我解释下 这个函数的意思 25分就给他了25分给BeenZ大哥做辛苦钱了
      

  11.   

    ....还是不行么
    这个函数的意思是把当前classname去掉带"iehover\\b" 的字符串
      

  12.   

    是这个stuHover
    我说整个函数 
    我JS不会 正在学 55555声明变量声明 FOR循环什么的就不用解释了
      

  13.   

    document.styleSheets.length
    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); 
    这些都不太理解
      

  14.   


    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();
      

  15.   

    原来的正则其实应该没什么问题,\\b他匹配的实际上是\b,\\\\b确实是\\b的转义,所以可能是你哪个地方弄错了,再检查下
      

  16.   

    你这段代码的效果是鼠标移动上去动态切换一个CSS类以达到效果的变换
    在公司没仔细看你的代码,费这么多事... 以为是转义问题.
    其实
    this.className=this.className.replace(new RegExp(" iehover\\b"), "");这个不用改,new RegExp(" iehover\\b")作用是匹配 以iehover结尾的字符串,replace(new RegExp(" iehover\\b"), "")就是将这个字符串替换为空.