您的位置:首页 > Web前端 > JavaScript

js把正在点击的输入栏变换背景颜色搜索

2016-04-21 00:00 671 查看
input和textarea

<script>
window.onload = function(){
listenInputFocus();
listenTextareaFocus();
}
//点击input后改变背景颜色
listenInputFocus = function(){
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
inputs[i].onfocus = function(){
this.style.backgroundColor = '#fff';
}
}
}
//点击textarea后改变背景颜色
listenTextareaFocus = function(){
var textareas = document.getElementsByTagName("textarea");
for (var tex = 0; tex < textareas.length; tex++) {
textareas[tex].onfocus = function(){
this.style.backgroundColor = '#fff';
}
}
}
</script>


//本文来源于网络,本人总结起来并优化,分享给有需要的前端朋友,如有侵权,请联系删除,也请指正、批评
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  输入栏