123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 'use strict';
- const table = document.createElement('table');
- for (let i = 0; i < 10; i++) {
- const tr = document.createElement('tr');
- for (let j = 1; j < 11; j++) {
- const td = document.createElement('td');
- td.id = String(i) + String(j);
- td.dataset.col = String(i);
- if (j === 10) {
- td.textContent = String(i);
- tr.prepend(td);
- continue;
- }
- td.textContent = String((i === 0 ? 1 : i) * j);
- tr.append(td);
- }
- table.append(tr);
- }
- document.body.append(table);
- table.onmouseover = function ({
- target: {
- cellIndex,
- tagName,
- id,
- dataset: { col },
- },
- }) {
- this.childNodes.forEach((element) => {
- element.childNodes.forEach((td) => {
- if (td.cellIndex === cellIndex) {
- td.style.backgroundColor = 'yellow';
- } else if (td.dataset.col === col) {
- td.style.backgroundColor = 'orange';
- } else {
- td.style.backgroundColor = 'grey';
- }
- });
- });
- if (tagName === 'TD')
- document.getElementById(id).style.backgroundColor = 'green';
- };
- const btnSubmit = document.getElementById('submitCalc');
- const resultP = document.getElementById('result');
- btnSubmit.addEventListener('click', updateValue);
- function updateValue(e) {
- const values = e.target.parentNode.children;
- resultP.textContent = String(+values[0].value * +values[1].value);
- }
- const firstInput = document.getElementById('first');
- const secondInput = document.getElementById('second');
- const hadleInputs = (e, inputValue) => {
- resultP.textContent = String(+e.target.value * +inputValue.value);
- };
- firstInput.addEventListener('change', (e) => hadleInputs(e, secondInput));
- secondInput.addEventListener('change', (e) => hadleInputs(e, firstInput));
|