欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js中清除字符串中某个字符串

程序员文章站 2022-04-15 13:28:24
#create ydds #date 2009-09-20 //remove src target function removestrwithcomma(srcstr, targetstr){...

#create ydds
#date 2009-09-20
//remove src target
function removestrwithcomma(srcstr, targetstr){
    var returnstr = '';
    if (srcstr == null || srcstr == '' || srcstr == undefined) {
        return returnstr;
    }
    else
        if (srcstr.indexof(targetstr) == -1) {
            return srcstr;
        }
        else {
            var srcstrs = srcstr.split(',');
            if (srcstrs.length == 1) {
                returnstr = '';
            }
            else
                if (srcstr.match(eval("/^" + targetstr + ".*/")) != null) {
                    returnstr = srcstr.replace(targetstr + ',', '');
                }
                else
                    if (srcstr.match(eval("/.*" + targetstr + "$/")) != null) {
                        returnstr = srcstr.replace(',' + targetstr, '');
                    }
                    else {
                        returnstr = srcstr.replace(',' + targetstr, '');
                    }
            return returnstr;
        }
}
var xmlhttplink;
function createxmllinkhttprequest(){
    if (window.activexobject) {
        xmlhttplink = new activexobject("microsoft.xmlhttp");
    }
    else
        if (window.xmlhttprequest) {
            xmlhttplink = new xmlhttprequest();
        }
}
本文出自 “一灯” 博客