javascript生成/解析dom的CDATA类型的字段的代码
javascript生成/解析dom的CDATA类型的字段的代码
发布时间:2016-12-30 来源:查字典编辑
摘要:两段demo代码如下(forieonly)://demo1varxmlDoc=newActiveXObject("Msxml2.DOMDoc...

两段demo代码如下(forieonly):

<scripttype="text/javascript">

//demo1

varxmlDoc=newActiveXObject("Msxml2.DOMDocument");

varroot;

varCDATASection;

xmlDoc.async=false;

xmlDoc.loadXML("<a/>");

root=xmlDoc.documentElement;

CDATASection=xmlDoc.createCDATASection("HelloWorld!");

root.appendChild(CDATASection);

b=xmlDoc.createElement("Test")

b.text="hahahahaha"

root.appendChild(b);

alert(root.xml);

for(i=0;i<root.childNodes.length;i++)

{

if(root.childNodes[i].nodeType==4)

alert(root.childNodes[i].nodeValue)

}

</script>

<scripttype="text/javascript">

//demo2

varxmlDoc=newActiveXObject("Msxml2.DOMDocument");

xmlDoc.async=false;

xmlDoc.loadXML("<a><![CDATA[aaaaaaaaaaaaaaaaaaaaa]]></a>");

root=xmlDoc.documentElement;

for(i=0;i<root.childNodes.length;i++)

{

if(root.childNodes[i].nodeType==4)

alert(root.childNodes[i].nodeValue)

}

</script>

//demo3(forfirefox)

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">

<HTML>

<HEAD>

<TITLE>使firefox对xml的处理兼容IE的selectSingleNodeselectNodes方法</TITLE>

<METANAME="Author"CONTENT="emu">

<METANAME="Keywords"CONTENT="firefoxIEselectSingleNodeselectNodes">

<METANAME="Description"CONTENT="使firefox可以支持selectSingleNodeselectNodes方法">

<SCRIPTLANGUAGE="JavaScript">

<>

</SCRIPT>

</HEAD>

<BODY>

</BODY>

</HTML>

//demo4(crossbrower)

http://kb.mozillazine.org/XPath

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类