用JS控制表格颜色变化
2008-08-30 12:32
477 查看
在一个注册页面如果没有填写,则要提示用户填写,显示浅红色提示,填写好了,变成无背景色。代码如下:
<html>
<script language="JavaScript">
function init(){
alert("init");
for (i=0;i<document.all.tags("Input").length;i++)
{
obj=document.all.tags("Input")[i];
if((obj.value.replace(/(^/s*)|(/s*$)/g,"")=="")) {
document.all.tags("Input")[i].style.backgroundColor="#ffcccc";
}
}
}
function notEmptyColor(obj){
if(obj.value.replace(/(^/s*)|(/s*$)/g,"")!=""){
obj.style.backgroundColor="#ffffff";
}
if(obj.value.replace(/(^/s*)|(/s*$)/g,"")==""){
obj.style.backgroundColor="#ffcccc";
}
}
</script>
<body onload="init()">
<table border="1" width="100" >
<tr><td>username</td><td><input type="text" onChange="notEmptyColor(this)" /></td></tr>
<tr><td>password</td><td><input type="text" onChange="notEmptyColor(this)"/></td></tr>
<tr><td>password2</td><td><input type="text" onChange="notEmptyColor(this)" /></td></tr>
</table>
</body>
</html>
<html>
<script language="JavaScript">
function init(){
alert("init");
for (i=0;i<document.all.tags("Input").length;i++)
{
obj=document.all.tags("Input")[i];
if((obj.value.replace(/(^/s*)|(/s*$)/g,"")=="")) {
document.all.tags("Input")[i].style.backgroundColor="#ffcccc";
}
}
}
function notEmptyColor(obj){
if(obj.value.replace(/(^/s*)|(/s*$)/g,"")!=""){
obj.style.backgroundColor="#ffffff";
}
if(obj.value.replace(/(^/s*)|(/s*$)/g,"")==""){
obj.style.backgroundColor="#ffcccc";
}
}
</script>
<body onload="init()">
<table border="1" width="100" >
<tr><td>username</td><td><input type="text" onChange="notEmptyColor(this)" /></td></tr>
<tr><td>password</td><td><input type="text" onChange="notEmptyColor(this)"/></td></tr>
<tr><td>password2</td><td><input type="text" onChange="notEmptyColor(this)" /></td></tr>
</table>
</body>
</html>
相关文章推荐
- js控制导航背景与字体颜色变化
- js控制表格颜色
- 用JS控制表格的交替颜色
- js控制表格单双行颜色交替显示
- css控制 表格颜色交替
- js控制鼠标移动到表格的某一行时改变该行的背景色
- js控制div颜色
- CSS+JS控制Li背景颜色交替
- Jquery 实现表格颜色交替变化鼠标移过颜色变化实例
- 简单的JS控制button颜色随点击更改
- Color.js增强你对颜色的控制
- JS控制TABLE表格在任意一行下面添加一行(有待完善)
- 表格的hover效果,IE6下用JS解决。--- 当鼠标移动到表格行时出现行背景颜色。
- JS控制表格实现一条光线流动分割行的方法
- 鼠标浮动到表格的某行 背景颜色变化[mouseover mouseout 以及mouseenter mouseleave]
- js 键盘控制表格input上下左右移动
- JS控制表格的列显示和隐藏
- JS控制网页动态生成任意行列数表格的方法
- js动态表格数据动态设置颜色
- QT控制选中item的文字颜色(HighlightedText) 和 QT表格交替背景色