How to extract text from Link in Javascript?

后端 未结 4 453
鱼传尺愫
鱼传尺愫 2021-01-27 14:08

I have following string:

StackOverFlow

How can I extract text (i.e. StackOver

4条回答
  •  深忆病人
    2021-01-27 14:39

    window.onload = function(){
        var text = 'StackOverFlow';
        var parser = null;
        if (window.DOMParser){
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(text,"text/xml");
        } else{ // Internet Explorer
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(text); 
        }
        var a = xmlDoc.childNodes[0];
        alert(a.childNodes[0].nodeValue);
    }
    

    http://www.w3schools.com/dom/dom_parser.asp

提交回复
热议问题