有对文本框进入和离开的事件 - asp.net? [英] is there enter and leave event on TextBox - asp.net?

查看:104
本文介绍了有对文本框进入和离开的事件 - asp.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有输入和一个asp.net文本框离开事件?

Is there enter and leave event on an asp.net TextBox?

我需要的,当我在文本框中单击,文本框的颜色会发黄,当我离开的颜色会变白。

I need that when i click on the TextBox, the TextBox color will be yellow and when I leave the color will be white.

我怎样才能做到这一点?

How can I do this?

推荐答案

使用jQuery来处理这个问题,还有,你需要两个事件。的onfocus和的onblur。

Use jQuery to handle this, there are two events that you need. onfocus and onblur.

<script type="text/javascript">
$(document).ready(function () {
    $('input').focus(function () {
        $(this).addClass('yellowBackground');
    });
    $('input').blur(function () {
        $(this).removeClass('yellowBackground');
    });
});

下面是CSS柜面你想知道:

Here is the CSS incase you were wondering:

<style type="text/css">
.yellowBackground 
{
    background:yellow;
}
</style>

修改

在你的问题中的关键字事件使我原本建议使用JavaScript,但可以在CSS中使用来实现:焦选择:
输入:焦点{背景颜色:黄色}

The keyword "event" in your question made me originally suggest using javascript, but this can be achieved in CSS using the :focus selector: input:focus { background-color: yellow }

https://jsfiddle.net/3dLp0f03/

这篇关于有对文本框进入和离开的事件 - asp.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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