지금은 새로운 HTML5 책 (Peter Kröner의 HTML5, Webseiten innovativ und zukunftssicher)을 읽었습니다. HTML5를 이해하기 위해 IE6-8을 가르치는 방법에 대한 몇 가지 예가 있습니다. (자바 스크립트가 활성화 된 경우) 한 가지 전략은 다음과 같습니다왜 string.replace가 변수를 포함하는 함수를 올바르게 실행하는지 이해할 수 없습니까?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 in IE</title>
<script>
'abbr article aside audio canvas details figcaption
figure footer header hgroup mark menu meter nav
output progress section summary time video'
.replace(/\w+/g, function(n) {window.document.createElement(n)});
</script>
</head>
<body>
<section>
<header>
<h1>This is the header</h1>
</header>
<section>
<h2>Chapter 1</h2>
<p>
Text, Text, Text, Text, Text...
Text, Text, Text, Text, Text...
Text, Text, Text, Text, Text...
Text, Text, Text, Text, Text...
</p>
</section>
<footer>
<p>
This is the footer.
</p>
</footer>
</section>
</body>
</html>
내가 IE의 디버거를 열 때 DOM이 올바른 것입니다. JS 함수를 생략하면 DOM이 손상됩니다. 그래서이 예제가 작동합니다. 이해가 안되는 부분은이 대체 문이 실제로 어떻게 작동하는지입니다. string.replace 권리를 이해하면 함수 자체로 문자열을 대체해야하지만 분명히 window.document.createElement가 바뀌었고 각 "태그"와 함께 올바르게 실행되어 각 "태그"가 함수에 의해 구문 분석되었습니다. 왜이게 효과가 있니?
IE6-8? 음? –
그 이유는 무엇입니까? – Bevor