//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";
}
写一个样式
.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";//变成红色
}
}