如何在onfocus时更改文本框的背景颜色?

编程入门 行业动态 更新时间:2024-10-25 21:18:22
本文介绍了如何在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时更改文本框的背景颜色?

本文发布于:2023-06-09 04:10:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/594960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   颜色   背景   如何在   onfocus

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!