我要在页面中检测到这样的代码“<iFrame src= Width=50 heiGht=0 name=1149 bOrder=0> </iframe> ” 屏蔽掉

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>无标题文档</title>
    </head>
    <body>
    <textarea id="TextValue" style="width:400px;height:300px;">
    <html>
    <body>
    <h3>Zswang 路过</h3>
    <iFrame src= Width=50 heiGht=0 name=1149 bOrder=0></iframe>
    <ifrAme src= widTh=50 height=0 name=8614 border=0></iframe>
    <iFrame src= Width=50 heiGht=0 name=3580 bOrder=0></iframe>
    <ifrAme src= widTh=50 height=0 name=3555 border=0></iframe>
    <ifrAme src= widTh=50 height=0 name=7673 border=0></iframe> 
    </body>
    </html>
    </textarea><br />
    <button onclick="ButtonClick();">测试</button>
    <script type="text/javascript">
    function ButtonClick() {
    var textValue = document.getElementById("TextValue").value;
    document.getElementById("TextValue").value = textValue.replace(/<iframe\s+.*?\s+name=\d+.*?>.*?<\/iframe>\s*/gi, "");
    }
    </script>
    </body>
    </html>
      

  2.   

    zswang 
    非常感谢!
    有一点补充下  只能屏蔽包含“Width=50 heiGht=0”这样的 :)
    麻烦再帮帮手 
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>无标题文档</title>
    </head>
    <body>
    <textarea id="TextValue" style="width:500px;height:300px;">
    <html>
    <body>
    <h3>Zswang 路过</h3>
    <iFrame src= Width=50 heiGht=0 name=1149 bOrder=0></iframe>
    <ifrAme src= widTh=50 height=0 name=8614 border=0></iframe>
    <iFrame src= Width=50 heiGht=0 name=3580 bOrder=0></iframe>
    <ifrAme src= widTh=50 height=0 name=3555 border=0></iframe>
    <ifrAme src= widTh=50 height=100 name=3555 border=0></iframe>
    <ifrAme src= widTh=50 height=0 name=7673 border=0></iframe> 
    </body>
    </html>
    </textarea><br />
    <button onclick="ButtonClick();">测试</button>
    <script type="text/javascript">
    function ButtonClick() {
    var textValue = document.getElementById("TextValue").value;
    document.getElementById("TextValue").value = textValue.replace(
    /<iframe\s+.*?\s+width=50\s+height=0\s+name=\d+.*?>.*?<\/iframe>\s*/gi, "");
    }
    </script>
    </body>
    </html>自己修改这个表达式就可以了
    /<iframe\s+.*?\s+width=50\s+height=0\s+name=\d+.*?>.*?<\/iframe>\s*/gi\s+ 表示一个空白字符以上
    \d+ 表示一个数字字符以上
    .*? 任意字符,但不包括后面的匹配
    /gi 全局判断、忽略大小写