我从Word生成了一些丑陋的HTML,我想从中删除所有HTML注释.
HTML看起来像这样:
<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>NO-BOK</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]-->
Run Code Online (Sandbox Code Playgroud)
..我正在使用的正则表达式就是这个
html = html.replace(/<!--(.*?)-->/gm, "")
Run Code Online (Sandbox Code Playgroud)
但似乎没有匹配,字符串不变.
我错过了什么?
我有一些javascript来测试DOM节点类型,如下所示:
if(node.nodeType == Node.TEXT_NODE) {
Run Code Online (Sandbox Code Playgroud)
当然,它在Firefox,Safari和Opera中都运行良好.但是,Internet Explorer 7抱怨Node(使用大写N)是未定义的.但这是DOM Level 2的一部分!
我是否真的需要更改我的代码以使用幻数?或者我在这里想念一些简单的东西?
我正在寻找一种方法,用jQuery将一个元素包装到注释中,如:
<!--
<div class="my_element"></div>
-->
Run Code Online (Sandbox Code Playgroud)
还有一种删除评论的方法.
这可能吗?因为我找不到任何相关的东西.
我在网站上工作.它包含很多评论.当用户view page source在任何浏览器中单击时,我想隐藏或删除评论html.
这可能吗?如果可能的话,有人会说一种实现它的方法.
谢谢.