本帖最后由 fengyu2004_4 于 2014-07-24 23:19:31 编辑

解决方案 »

  1.   

    var str="第<SPAN id=topic_4>1</SPAN>题:"
    var reg=/id=topic_(\d+)/;
    var arr=reg.exec(str);
    var s=['零','一','二','三','四','五','六','七','八','九']
    if(arr&&arr.length>0){
    str=s[arr[1]];
    }
    alert(str);
      

  2.   

    str="<DIV class=tChange>"
    str=str+"<<DIV onclick=switchTflag(1,1); class=first></DIV>"
    str=str+"<DIV onclick=switchTflag(1,1); class=previous></DIV>"
    str=str+"<DIV onclick=switchTflag(1+1,1); class=next></DIV>"
    str=str+"<DIV onclick=switchTflag(70,4); class=last></DIV>"
    str=str+"</DIV>"
    var div=document.createElement('div');
    div.innerHTML=str;
    div.removeChild($('.tChange')[0]);
    alert(div.innerHTML);
      

  3.   

    var str="第<SPAN id=topic_1>1</SPAN>题:第<SPAN id=topic_2>1</SPAN>题:第<SPAN id=topic_4>1</SPAN>题:"
    var nums=['零','一','二','三','四','五','六','七','八','九','十']
    str=str.replace(/<SPAN id=topic_(\d)+>.*?<\/SPAN>/ig,function(s){s=s.match(/id=topic_(\d)+>/i);return nums[parseInt(s[1],10)]; });
    alert(str); str="html htmlhtmlhtml<DIV class=tChange>"
    str=str+"<DIV onclick=switchTflag(1,1); class=first></DIV>"
    str=str+"<DIV onclick=switchTflag(1,1); class=previous></DIV>"
    str=str+"<DIV onclick=switchTflag(1+1,1); class=next></DIV>"
    str=str+"<DIV onclick=switchTflag(70,4); class=last></DIV>"
    str=str+"</DIV>替换"
    alert(str.replace(/<DIV class=tChange>[\d\D]*?<\/DIV>\s*<\/DIV>/i,""))
      

  4.   

    经测试,以上的方法都可以的,但有一个问题就是“字符串”我是用asp生成的,如果是IE浏览器,上面的代码可以达到我要的效果,可以替换掉成空;但是如果是firefox浏览器,它默认会加上“双引号”,比如:<DIV class=tChange>asp输出之后,它会变成<DIV class=“tChange”>多了双引号,结果就替换不掉,这样,往往,这样的relace我得写2次重复的语句代码,很麻烦,有没有办法只写一次的代码就可以的???下面就是我现写的2次重写的代码:str.replace(/<DIV class=tChange>[\d\D]*?<\/DIV>\s*<\/DIV>/i,"")) //针对ie浏览器
    str.replace(/<DIV class="tChange">[\d\D]*?<\/DIV>\s*<\/DIV>/i,"")) //针对firefox浏览器(tChange多一个“双引号”的处理)万分感谢,这个解决完,就结贴了~~呵呵
      

  5.   

    str.replace(/<DIV class="?tChange"?>[\d\D]*?<\/DIV>\s*<\/DIV>/i,"")) 
     
      

  6.   

    非常感谢各位高手的相助,终于解决了,谢谢你们~!也谢谢csdn这个平台 !