本文介绍了如何在onfocus时更改文本框的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过这个代码,但它不工作..当我的焦点文本框它显示错误
i tried this code but its not working.. when i on-focus textbox it shows error
function ChangeBgColor(obj, evt) { if(evt.type=="focus") style.background ="lightgrey"; else if(evt.type=="blur") { style.background="white"; } }推荐答案
是 style ?您尚未在上述代码中的任何位置定义它:
What is style? You have not defined it anywhere in your code above:
function ChangeBgColor(obj, evt) { if(evt.type=="focus") style.background ="lightgrey"; //<--what is style? else if(evt.type=="blur") { style.background="white"; } }我猜你想要像
obj.style.background ="lightgrey";在上面的代码中,简化了
And in the code above, simplified
function ChangeBgColor(obj, evt) { obj.style.background = (evt.type=="focus") ? "lightgrey" : "white"; }最好的答案是使用纯CSS。
The best answer is to use pure CSS.
更多推荐
如何在onfocus时更改文本框的背景颜色?
发布评论