使用AhtuHotkey 2.0 Beta1(我假设VBA脚本也是如此)getElementsByTagName()
只显示HTML5标签section
和nav
的开始标签,但与所有其他HTML4标签一起工作。
AutoHotkey代码
HTMLObj := ComObject("HTMLfile")
HTMLObj.write(HTML)
DOMObj := HTMLFileObj.getElementsByTagName("section")
msgbox DOMObj[0].outerHTML
下面将返回只是打开标签<section class=mysection>
我认为它根本不知道如何处理HTML5标签。是否有解决方案,我是在Windows 7 x64服务包1
旧版本的IE(HTML解析器)默认将未知元素视为内联元素。这意味着一旦遇到下一个已知的块元素,解析器就会自动关闭它们。
试试这个(一个更全面的简单版本https://github.com/aFarkas/html5shiv):
html5shim =
(
<script>
document.createElement('header');
document.createElement('section');
document.createElement('main');
document.createElement('article');
document.createElement('aside');
document.createElement('nav');
document.createElement('footer');
</script>
)
HTMLObj := ComObject("HTMLfile")
HTMLObj.write(html5shim)
HTMLObj.write(HTML)
DOMObj := HTMLFileObj.getElementsByTagName("section")
msgbox DOMObj[0].outerHTML
另一种方法是添加CSS将这些元素声明为块元素:
<style type="text/css">
header, section, main, article, aside, nav, footer { display: block; }
</script>