let spanEle = document.getElementsByTagName('span')[0];
let inputEle = document.getElementsByTagName('input')[0];
let divEle = document.getElementsByTagName('div')[0];
let spanEle1 = [...divEle.children];
inputEle.addEventListener('input', e => {
let inputValue = inputEle.value;
if (inputValue.length <= 3) {
yanse(0, 'green');
}
if (inputValue.length > 3 && inputValue.length <= 6) {
yanse(1, 'yellow');
}
else if (inputValue.length > 6) {
yanse(2, 'red');
}
})
spanEle.addEventListener('click', () => {
inputEle.type=='text'?inputEle.type='password':inputEle.type='text';
})
function yanse(index, yanse) {
spanEle1.map(a => a.style.backgroundColor = 'transparent');
spanEle1[index].style.backgroundColor = yanse;
}
<label for="" >请输入</label>
<input type="password">
<span>🐉</span>
<div>
<span>弱</span>
<span>中</span>
<span>强</span>
</div>