let first = document.getElementById('firstInput'); //первое поле
let two = document.getElementById('twoInput'); //второе поле
function preventInput(input) {
input.addEventListener('keydown', handler)
}
function unPreventInput(input) {
input.removeEventListener('keydown', handler)
}
function handler(e) {
e.preventDefault();
}
preventInput(two);
first.addEventListener('change', function(e) {
if (e.target.value == '') {
preventInput(two);
} else {
unPreventInput(two);
}
})
if (e.target.value.lenght < N)
let input = document.body.firstElementChild;
let arr = ['test']
function findWord(input, arr, callback) {
input.addEventListener('input', function (e) {
arr.forEach(function(item, i, arr) {
if (input.value.indexOf(item) >= 0) {
callback(item);
}
})
})
}
function test(item) {
alert(item)
}
findWord(input, arr, test)
#elem:hover{
background-color: blue !important;
}
function render() {
countField.value = countFieldValue;
}
countMinus.addEventListener('click', function() {
countFieldValue--;
render()
});
countPlus.addEventListener('click', function() {
countFieldValue++;
render()
});
function getWidth(id) {
let input = document.getElementById(id)
let fontSize = getComputedStyle(input);
let newSpan = document.createElement('span');
newSpan.style.fontSize = fontSize;
newSpan.style.margin = '0px';
newSpan.style.padding = '0px';
newSpan.innerHTML = input.value || input.getAttribute('placeholder');
document.body.appendChild(newSpan);
let width = newSpan.offsetWidth;
newSpan.remove()
return width;
}
let elem = document.getElementById('ID') //ID инпута
let width = getWidth(elem) //переменная будет равна длинне в px