//input背景被选中变色 var input = document.getElementById(‘input‘); var btn = document.querySelectorAll(‘button‘)[0]; btn.onclick= function(){ input.style.backgroundColor = ‘blue‘ } //input背景不变色(没被选中) var input = document.querySelectorAll(‘#input‘); var btn = document.querySelectorAll(‘button‘)[0]; btn.onclick= function(){ input.style.backgroundColor = ‘blue‘ } //input背景变色 var input = document.querySelectorAll(‘#input‘)[0]; var btn = document.querySelectorAll(‘button‘)[0]; btn.onclick= function(){ input.style.backgroundColor = ‘blue‘ }
//确认密码 function passwordConfirm() { var input = confirm.querySelectorAll(‘input‘)[0]; // var inputValue = confirm.querySelectorAll(‘input‘)[0].value; //inputValue为初始化密码栏的值,理清楚顺序! var span = confirm.querySelectorAll(‘span‘)[0]; //var firstP = password.querySelectorAll(‘input‘)[0]; var firstP = password.querySelectorAll(‘input‘)[0]; //聚焦时 input.onfocus = function () { span.innerHTML = ‘请再次输入密码‘; } //离开输入框时 input.onblur = function () { var cPassword = input.value; if(cPassword != ‘‘){ if ( cPassword == firstP.value ) { span.innerHTML = ‘密码一致‘; change(span, input, true) } else { span.innerHTML = ‘两次密码不一样‘ change(span, input, false) } }else{ span.innerHTML = ‘密码不能为空‘; change(span, input, false) } } }
原文:http://www.cnblogs.com/huangxingyuan/p/IFE.html