有一个文本框,一个提交按钮。单击按钮,文本框背景色变为红色,之后红色慢慢的淡出,文本框背景色又变为初始的颜色.
这个功能怎么实现?请大侠帮忙!
我的代码:$("#addacount_form div[id=create_account_operation] input[id=save_account]").click(function(){
var string=$("#addacount_form table[id=account_info_table] input[id=accountname]").val();
if($.trim(string)==""){
$("#addacount_form table[id=account_info_table] input[id=accountname]").addClass("backgroundcolor");
$("#addacount_form table[id=account_info_table] input[id=accountname]").fadeOut(1000, function(){
$("#addacount_form table[id=account_info_table] input[id=accountname]").removeClass("backgroundcolor");
});
}
});
这个功能怎么实现?请大侠帮忙!
我的代码:$("#addacount_form div[id=create_account_operation] input[id=save_account]").click(function(){
var string=$("#addacount_form table[id=account_info_table] input[id=accountname]").val();
if($.trim(string)==""){
$("#addacount_form table[id=account_info_table] input[id=accountname]").addClass("backgroundcolor");
$("#addacount_form table[id=account_info_table] input[id=accountname]").fadeOut(1000, function(){
$("#addacount_form table[id=account_info_table] input[id=accountname]").removeClass("backgroundcolor");
});
}
});
<input id="effect"/ >
<input type="button" id="button" />
$(function()
{
$("#button").toggle(
function()
{
$("#effect").animate({ backgroundColor: '#aa0000', color: '#fff', width: 500 }, 1000);
},
function()
{
$("#effect").animate({ backgroundColor: '#fff', color: '#000', width: 240 }, 1000);
}
);
});
<script language="javascript">
$(function()
{
$("#button").click(function()
{
$("#effect").addClass("class1", 500, function()
{
$("#effect").removeClass("class1", 500);
});
});
}); </script> <style type="text/css">
.class1
{
background-color: #FF3300;
}
</style>
</head>
<body>
<input id="effect" />
<input type="button" id="button" value="点击改变样式" />
</body>
<textarea id="test" cols="30" rows="3"></textarea>
<input type="button" id="btn" value="提交" />
<div id="test1" style="width:200px; height:200px; border:1px solid red; "></div>
$("#btn").click(function(){
$("#test").animate({"backgroundColor":'#333333',color:'#999', width:500}, 1000);
$("#test1").animate({"backgroundColor":'#333333',color:'#999', width:500}, 1000);
});证明此函数不支持背景变色
.class1{背景样式}
.class2{边框样式}
add和remove的时候只操作class1
addClass确实有好多参数,你可以去查查资料,jq的demos里有
border:5px solid red;
}就可以了
startColorStr='deepskyblue', endColorStr='#FFFFFF', gradientType='0')">
setTimeout(function(){
$("#文本框ID").animate({background-color:#fff },1000)
},1000);
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var timer1,timer2;
var gColor=0;
var bColor=0;
var newColor;
var objID;
var obj;
function clickEvent(objID)
{
this.objID = objID;
changeColor();
timer1=setTimeout("fadeOutColor()",1000);
}
function changeColor()
{
obj = document.getElementById(objID);
if (obj.value == "")
{
obj.style.background = "#ff0000";
}
}
function fadeOutColor()
{
obj = document.getElementById(objID);
clearTimeout(timer1);
gColor+=20;
bColor+=20;
if(gColor>255)
{
gColor =255;
}
if(bColor>255)
{
bColor =255;
clearTimeout(timer2);
}
newColor = toHex(gColor)+toHex(bColor);
obj.style.background = "#ff"+newColor;
timer2=setTimeout("fadeOutColor()",200);
}
function toHex(num)
{
var tt,t,hh,h;
tt = Math.floor(num/16);
t =num % 16;
switch(tt)
{
case 10:
hh="A";
break;
case 11:
hh ="B";
break;
case 12:
hh ="C";
break;
case 13:
hh ="D";
break;
case 14:
hh ="E";
break;
case 15:
hh ="F";
break;
default:
hh =tt.toString();
break;
}
switch(t)
{
case 10:
h="A";
break;
case 11:
h ="B";
break;
case 12:
h ="C";
break;
case 13:
h ="D";
break;
case 14:
h ="E";
break;
case 15:
h ="F";
break;
default:
h =t.toString();
break;
}
return (hh+h);
}
</script>
</head><body>
<form name="form1" method="post" action="">
<input type="text" name="test" id="test" onclick="clickEvent('test');"/>
</form>
</body>
</html>
$("#arrow1").attr("src", "image/arrow/4c.gif");
});
不过不要忘记引用库
function clickEvent(objID)
{
this.objID = objID;
changeColor();
timer1=setTimeout("fadeOutColor()",1000); gColor=0;
bColor=0;
}
<INPUT TYPE="button" VALUE="提交" ONCLICK="check()"> <SCRIPT LANGUAGE="JavaScript">
<!--
var inp = document.getElementById("inp")
var intv;
function check() {
if (inp.getAttribute("value") == "")
{
inp.style.backgroundColor="#FF0000";
setTimeout("intv = setInterval('fade()',100)",1000);
}
}
function fade(){
var gbcode = "0x"+ inp.style.backgroundColor.substring(3);
if(gbcode == "0xffff"){
window.clearInterval(intv);
alert("完成!");
return;
}
gbcode = (+(gbcode) + 0x1111).toString(16);
inp.style.backgroundColor = "#ff" + gbcode;
}
//-->
</SCRIPT>
<script src="../JQueryJS/jquery-1.4.2.js" type="text/javascript"></script><script src="../JQueryJS/jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script><script language="javascript">
$(function()
{
$("#button").click(function()
{
if ($("#effect").val() == "")
{
$("#effect").addClass("class2");
$("#effect").addClass("class1", 200, function()
{
$("#effect").removeClass("class1", 200);
});
}
else
{
$("#effect").removeClass("class2");
} }
); });</script><style type="text/css">
.class1
{
background-color: #FF3300;
}
.class2
{
border: 2px solid red;
}
</style>
</head>
<body>
<input id="effect" />
<input type="button" id="button" value="点击改变样式" />
</body>