Sandbox: Difference between revisions
From Hidden Mickey Wiki
No edit summary |
No edit summary |
||
| Line 5: | Line 5: | ||
|- | |- | ||
| Example task 1 | | Example task 1 | ||
| <input type="checkbox" class="mw-checkbox-ts" /> | | <htmltag tagname="input" type="checkbox" class="mw-checkbox-ts"></htmltag> | ||
| <span class="mw-ts-box"></span> | | <span class="mw-ts-box"></span> | ||
|- | |- | ||
| Example task 2 | | Example task 2 | ||
| <input type="checkbox" class="mw-checkbox-ts" /> | | <htmltag tagname="input" type="checkbox" class="mw-checkbox-ts"></htmltag> | ||
| <span class="mw-ts-box"></span> | | <span class="mw-ts-box"></span> | ||
|- | |- | ||
| Example task 3 | | Example task 3 | ||
| <input type="checkbox" class="mw-checkbox-ts" /> | | <htmltag tagname="input" type="checkbox" class="mw-checkbox-ts"></htmltag> | ||
| <span class="mw-ts-box"></span> | | <span class="mw-ts-box"></span> | ||
|} | |} | ||
<script> | <script> | ||
(function () { | (function () { | ||
'use strict'; | 'use strict'; | ||
function formatTime(d) { | function formatTime(d) { | ||
return d.toLocaleTimeString('en-US', { | |||
hour: 'numeric', | |||
minute: '2-digit', | |||
second: '2-digit' | |||
}); | |||
} | |||
} | } | ||
function findTsBox(cb) { | function findTsBox(cb) { | ||
var tr = cb.closest('tr'); | var tr = cb.closest('tr'); | ||
return tr ? tr.querySelector('.mw-ts-box') : null; | |||
} | } | ||
document.addEventListener('change', function (ev) { | document.addEventListener('change', function (ev) { | ||
var | var cb = ev.target; | ||
if ( | if (cb.matches && cb.matches('.mw-checkbox-ts')) { | ||
var tsBox = findTsBox(cb); | |||
var tsBox = findTsBox( | if (tsBox) tsBox.textContent = cb.checked ? formatTime(new Date()) : ''; | ||
if ( | |||
} | } | ||
}, false); | }, false); | ||
})(); | })(); | ||
</script> | </script> | ||
Revision as of 15:48, 30 September 2025
| Item | Done | Time |
|---|---|---|
| Example task 1 | ||
| Example task 2 | ||
| Example task 3 |
<script> (function () {
'use strict';
function formatTime(d) {
return d.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
second: '2-digit'
});
}
function findTsBox(cb) {
var tr = cb.closest('tr');
return tr ? tr.querySelector('.mw-ts-box') : null;
}
document.addEventListener('change', function (ev) {
var cb = ev.target;
if (cb.matches && cb.matches('.mw-checkbox-ts')) {
var tsBox = findTsBox(cb);
if (tsBox) tsBox.textContent = cb.checked ? formatTime(new Date()) : ;
}
}, false);
})(); </script>