@todojs/

04.javascript

HTML, CSS, JS

No description

fork
loading
Files
  • index.html
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="test"></div>
<pre></pre>
<script>
  const div = document.querySelector ('#test');
  div.attachShadow ({mode : 'open'});

  const script     = document.createElement ('script');
  script.innerHTML = 'var a = 10';
  div.shadowRoot.appendChild (script);

  const result = document.querySelector('pre');
  result.innerHTML = 'window.a ===' + window.a;
</script>
</body>
</html>
result
console