| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>055 inline event attributes</title>
- <style>
- body { background: #ffffff; color: #202020; font-family: sans-serif;
- margin: 12px; font-size: 18px; }
- #result { background: #ffc8c8; color: #000000; padding: 8px;
- margin-top: 12px; }
- </style>
- </head>
- <body>
- <h1>055 — inline event attributes</h1>
- <p><code>onclick</code> must run with the element as <code>this</code>, bubble
- to an ancestor handler, and <code>return false</code> must prevent the
- default action.</p>
- <button id="button" onclick="this.setAttribute("data-x", "1"); this.textContent = 'clicked'; window.__inline = (window.__inline || 0) + 1;">press me</button>
- <div id="parent" onclick="window.__bubbled = (window.__bubbled || 0) + 1;">
- <span id="child">bubble source</span>
- </div>
- <a id="cancel" href="#somewhere" onclick="return false;">cancel link</a>
- <div id="result">checking...</div>
- <script>
- setTimeout(function () {
- var b = document.getElementById('button');
- var p = document.getElementById('parent');
- var c = document.getElementById('child');
- var a = document.getElementById('cancel');
- b.dispatchEvent(new MouseEvent('click', { bubbles: true }));
- c.dispatchEvent(new MouseEvent('click', { bubbles: true }));
- var notCancelled = a.dispatchEvent(new MouseEvent('click', {
- bubbles: true, cancelable: true
- }));
- var ok = b.textContent === 'clicked' &&
- b.getAttribute('data-x') === '1' &&
- window.__inline === 1 &&
- window.__bubbled === 1 &&
- notCancelled === false;
- var r = document.getElementById('result');
- if (r) {
- r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
- r.textContent = (ok ? 'INLINE-OK ' : 'INLINE-FAIL ') +
- 'text=' + b.textContent +
- ' x=' + b.getAttribute('data-x') +
- ' inline=' + window.__inline +
- ' bubble=' + window.__bubbled +
- ' dispatch=' + notCancelled;
- }
- }, 300);
- </script>
- </body>
- </html>
|