textbox样式 CSS高手进

2025-05-09 03:36:10
推荐回答(2个)
回答1:

//cs代码给textbox控件添加属性
textbox.Attributes.Add("onpropertychange","changeBorder(this)");
textbox.Attributes.Add("oninput","changeBorder(this)");

//css样式
.demo{border:solid 1px Red;}

//页面文件添加js方法
function changeBorder(textbox)
{
if(textbox.value=="") textbox.className="";
else textbox.className="demo";
}

回答2:

写一个样式
.demo{border:solid 1px Red;}
用脚本控制
onpropertychange=changeBorder(this)(在IE中)
oninput=changeBorder(this)(在FireFox中),为求兼容,在textbox的属性里两个都写上。
函数如下:
changeBorder(obj){
if(obj.value==""){
obj.className="";//变为默认
}else{
obj.className="demo";//变成红色
}
}