更改所需的文本框背景色 [英] change required textbox background color

查看:145
本文介绍了更改所需的文本框背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我的页面上大约有10到15个文本框,它们都是必需的.谁能告诉我如何更改它们的焦点上的背景色?我可以使用getElementById做到这一点,但我不想获取每个ID.我只想将控件(例如文本框或下拉列表)发送给函数并更改控件的背景色.


如果有人在这方面帮助我,那将非常好.提前谢谢..

谢谢
Yogesh

Hi Friends,

I have around 10 to 15 textboxes on my page and they are all required. Can any one tell me how to change there background color onFocus of them? I can do it by using getElementById, but I don''t want to fetch every single id. I just want to send the control (say textbox or dropdownlist) to the function and change that controls background color.


It''ll be very great if someone help me on this. Thanks in advance..

Thanks
Yogesh

推荐答案

创建一个JavaScript函数,该函数将ControlID作为参数.
在函数中,设置已通过ControID的控件的背景色.
调用所需文本框的onfocus上传递其ID的函数.
Create a JavaScript function which will take ControlID as an argument.
In the function, set the background color of the control whose ControID has been passed.
Call the function on onfocus of the required textboxes passing its id.


嘿朋友,

我得到了答案.

在aspx页面的代码块中添加以下两个函数.

< pre lang ="javascript">& lt;脚本语言="javascript" type ="text/javascript">

函数DoBlur(fld)
{
fld.style.background =#FFFFFF";
}

函数DoFocus(fld)
{
//fld.className =``focusfld'';
fld.style.background =浅黄色";
}

& lt;/script></pre>

然后在页面上将这些功能应用于文本框或下拉列表的OnFocus和OnBlur属性,如下所示.

< pre lang ="xml">& lt; asp:textbox id ="txt1" runat ="server" onfocus ="DoFocus(this);" onblur ="DoBlur(this);" /& gt;</pre>

只要您专注于该控件,它就会更改该控件的颜色.以下代码将使文本框在未验证时集中显示.
< pre lang ="vb">
试试
''文本框的验证将在这里
异常捕获
txt1.Focus()
扔前
结束Try</pre>


希望这段代码能对需要这种功能的所有人有所帮助.

谢谢,
Yogesh
Hey Friends,

I got the answer for this.

Add the following 2 functions in block on aspx page.

<pre lang="javascript">&lt;script language="javascript" type="text/javascript">

function DoBlur(fld)
{
fld.style.background="#FFFFFF";
}

function DoFocus(fld)
{
//fld.className = ''focusfld'';
fld.style.background = "lightyellow";
}

&lt;/script></pre>

And on page apply these functions to textbox''s or dropdownlist''s OnFocus and OnBlur properties just like follows.

<pre lang="xml">&lt;asp:textbox id="txt1" runat="server" onfocus="DoFocus(this);" onblur="DoBlur(this);" /&gt;</pre>

Whenever you focus on that control it''ll change the color of that control. Following code will focus the textbox when it is not validate.
<pre lang="vb">
Try
''Validation of textbox will go here
Catch ex As Exception
txt1.Focus()
Throw ex
End Try</pre>


Hope this code will help everyone who required this kind of functionality.

Thanks,
Yogesh


这篇关于更改所需的文本框背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆