Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net asp文本框控件的CSS_Asp.net_Css_Textbox_Stylesheet - Fatal编程技术网

Asp.net asp文本框控件的CSS

Asp.net asp文本框控件的CSS,asp.net,css,textbox,stylesheet,Asp.net,Css,Textbox,Stylesheet,我有一个ASP文本框控件。当用户关注文本框时,我想将文本框的背景颜色从灰色更改为白色 这是css文件,但它在聚焦文本框后不会改变颜色 <script language="javascript" type="text-javascript"> function DoFocus(txt) { txt.className = 'focus'; } </script> 编辑:我看到你更新了你的帖子,为了澄

我有一个ASP文本框控件。当用户关注文本框时,我想将文本框的背景颜色从灰色更改为白色

这是css文件,但它在聚焦文本框后不会改变颜色

     <script language="javascript" type="text-javascript">
     function DoFocus(txt) 
     {
         txt.className = 'focus';
     }    
   </script>

编辑:我看到你更新了你的帖子,为了澄清:ASP创建了一个
输入
HTML元素(如果我错了,请纠正我),你可以通过CSS中的
:focus
选择器来设置样式,不需要Javascript,但也可以添加
输入。文本框:active
来捕获一些错误的IE

input.textbox:focus, input.textbox:active {
   /* everything you put here will be aplied to ANY focused input element */
}

从粘贴的代码判断,而不是

.input_text:focus, input.input_text_focus {
    border-color:#646464;
    background-color:#ffffc0;
}
使用


或者,当你有
input.textbox
第一手资料时,为什么突然使用class
input\u text
?您的两个选择器不匹配…

仅使用css无法实现这一点。您还必须使用javascript。例如:

<asp:TextBox runat="server" id="myTextbox" onfocus="DoFocus(this)" onblur="DoBlur(this)"></asp:TextBox>  
您可以在以下网址找到一些好例子:



这里是一种通过javascript指定的使用分离CSS类的方法:

<style type="text/css">
    input.FocusedStyle
    {
        background-color:#ffffc0;
        border-color:#646464;
    }
</style>

<script type="text/javascript">
    function OnBlur(textBox) {
        textBox.className = '';
    }
    function OnFocus(textBox) {
        textBox.className += ' FocusedStyle';
    }
</script>

<asp:TextBox ID="txt" runat="server" onblur="OnBlur(this);" onfocus="OnFocus(this);"></asp:TextBox>

input.FocusedStyle
{
背景色:#ffffc0;
边框颜色:#6464;
}
函数OnBlur(文本框){
textBox.className='';
}
函数OnFocus(文本框){
textBox.className+='FocusedStyle';
}

我已经按照你说的做了,但是没有用……我已经在主要帖子中编辑了代码……对不起。忘记更改css类名了。更新了答案,看看CSS类名。它应该是
focus
类型也应该是
text/javascript
。我的错!我只想问一件事,为什么在我手动将样式添加到aspx页面而不是样式表时高亮显示会起作用?这可能是因为有其他样式来自其他样式表。。。尝试使用
背景色:#ffffc0!重要的…我刚刚在我的页面中引用了一个样式表。我只是在我的项目中使用1,我还没有使用ASP,所以我不能告诉你它是否自己生成了一些默认样式表。另一个需要考虑的是浏览器有默认样式表,尝试包括<代码>重置。CSS < /代码>(谷歌IT;)。内联样式(直接在页面中输入)有效,因为它们更“具体”,您还可以尝试添加更多选择器,如
#内容表单输入。文本框:聚焦
如果您的表单包含在id为
内容的div中
…这是一个不错的答案,但总的来说,你应该试着留下一条评论来解释你做了什么。。。只有代码的答案是不受欢迎的。我知道这很旧,但这比使用JavaScript设置焦点要好得多。使用伪类。
input.textbox:focus, input.input_text_focus {
   ...
}
<asp:TextBox runat="server" id="myTextbox" onfocus="DoFocus(this)" onblur="DoBlur(this)"></asp:TextBox>  
<script language="javascript" type="text/javascript">
  function DoFocus(txt) 
  {
      txt.className = 'focus';
  }          

  function DoBlur(txt) 
  {
      txt.className = 'unfocus';
  }
</script>
input.textbox, select, textarea, unfocus
{
 font-family    :  verdana, arial, snas-serif;
 font-size      :  11px;
 color          :  #000000;
 padding        :  3px;
 background     :  #f0f0f0;
 border-left    :  solid 1px #c1c1c1;
 border-top     :  solid 1px #cfcfcf;
 border-right   :  solid 1px #cfcfcf;
border-bottom  :  solid 1px #6f6f6f;
}

.focus
{
    border-color:#646464;
    background-color:#ffffc0;
}  
<style type="text/css">
    input.FocusedStyle
    {
        background-color:#ffffc0;
        border-color:#646464;
    }
</style>

<script type="text/javascript">
    function OnBlur(textBox) {
        textBox.className = '';
    }
    function OnFocus(textBox) {
        textBox.className += ' FocusedStyle';
    }
</script>

<asp:TextBox ID="txt" runat="server" onblur="OnBlur(this);" onfocus="OnFocus(this);"></asp:TextBox>
  TEXTAREA, INPUT[type="text"]
  {
    font-family    :  tahoma, arial, snas-serif;
    font-size      :  11px;
    color          :  #000000;

    padding        :  3px;
    background     :  #EEEfff;
    border-left    :  solid 1px #c1c1c1;
    border-top     :  solid 1px #cfcfcf;
    border-right   :  solid 1px #cfcfcf;
    border-bottom  :  solid 1px #6f6f6f;
  }

  INPUT[type="text"]:focus, INPUT[type="text"]:active 
  {
      border-color:#646464;
      background-color:#ffcf03;
  }