在TextBox上有进入和离开事件 - asp.net吗?

Gol*_*old 1 c# asp.net

是否在asp.net TextBox上输入和离开事件?

我需要当我点击TextBox时,TextBox颜色将为黄色,当我离开时颜色将为白色.

我怎样才能做到这一点?

The*_*Man 5

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

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

这是您想知道的CSS问题:

<style type="text/css">
.yellowBackground 
{
    background:yellow;
}
</style>
Run Code Online (Sandbox Code Playgroud)

编辑

您的问题中的关键字"事件"使我最初建议使用javascript,但这可以使用:focus选择器在CSS中实现: input:focus { background-color: yellow }

https://jsfiddle.net/3dLp0f03/