谁能快速浏览一下这段代码,让我知道哪里出错了。
在模糊事件中,.textok
类加载正常,但 .textbad
类加载不正常。
<style>
.textok {
color:#0F0;
background-color:#093;
};
.textbad {
color:#F00;
background-color:#900;
};
</style>
<script>
$("#name").blur(function()
{
$.post("logval.php?type=name",{ name:$('#name').val() } ,function(data)
{
if(data=='noname') //if no username
{
$("#usererror").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$("#usererror").html('Name Accepted ').addClass("textbad").fadeTo(900,1);
$("#tic").attr("src","tic.gif").fadeTo(900,1);
});
} else
{
$("#usererror").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$("#usererror").html('Name Accepted ').addClass("textok").fadeTo(900,1);
$("#tic").attr("src","tic.gif").fadeTo(900,1);
});
}
});
})
</script>
最佳答案
在 CSS 中不要在大括号后加上分号:
.textok {
color:#0F0;
background-color:#093;
} /* No semicolon here! */
正是这些分号阻止了您的 CSS 被理解。
关于javascript - 帮助 ajax jquery css 事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7000654/