日期:2014-05-18  浏览次数:20455 次

问点问题请帮帮我~
//aspx
this.Text1.Attributes.Add( "onmouseover ",   "this.className= 'mouseovertext ' ");

CSS
.mouseovertext
{
      background-color:#ccffff;
}
现在样好使当光标移到Text1上时,颜色变成#ccffff
我想实现   窗体里有20多个text文本框.我想每个框都能这样
不想每个每个文本框加事件
有什么关法实现~~~~

------解决方案--------------------
写个伪代码
foreach(control c in this.controls)
{
//如果是TextBox控件
if(c.GetType()== "TextBox ")
{
//如果值为空
if(c.Text.Trim()== " ")
{
//怎怎地怎怎地
}
}
}

------解决方案--------------------
不想每个都加事件的话,那只有自己写个text控件了
如果要加上事件
可以参考
<input name= "txtUserName " type= "text " id= "txtUserName " onFocus= "this.className= 'colorfocus '; "
onBlur= "this.className= 'colorblur '; " size= "18 " maxLength= "30 ">


CSS.css

.colorfocus {
border: 1px #0099CC double;
background-color: #FFFF99;
padding:1px 1px 1px 1px;
}
.colorblur {
border: 1px #000000 double;
background-color: #ffffff;
}

------解决方案--------------------
我用03写了个函数。其实这种要求不需要放在服务器端,做效果js完全可以。
<script language= "javascript ">
function ss()
{
var sstr=document.getElementsByTagName( 'input ');
var j=0;
for(var i=0;i <sstr.length;i++)
{
var smt = sstr[i];
if(smt.getAttribute( 'type ')== "text ")
{
smt.onmouseover=function(){this.className= 'mouseovertext '};
}
}
}
</script>
把这个函数写在页面加载的里面,例如:body 的onload()里面
------解决方案--------------------
<script language= "javascript ">
function ss()
{
var sstr=document.getElementsByTagName( 'input '); for(var i=0;i <sstr.length;i++)
{
var smt = sstr[i];
if(smt.getAttribute( 'type ')== "text ")
{
smt.onmouseover=function(){this.className= 'mouseovertext '};
}
}
}
window.onload = function() { ss(); }
</script>