gpt4 book ai didi

javascript - 为什么 jQuery 背景动画不起作用?

转载 作者:行者123 更新时间:2023-11-30 07:05:47 25 4
gpt4 key购买 nike

我是一名初学者网页设计师,但我会尝试使用 JavaScript 和 jQuery。环顾四周W3Schools有一段时间,我尝试制作一个简单的 jQuery 动画,但它似乎不起作用。

<html>
<head>
<script type="text/javascript" src="jQuery.js"></script>
<script>
$(document).ready(function(){
$("#name").blur(funtion(){
if(value==null || value==""){
$("#name").animate({background:#D23E42}, "slow");
}
});
});
</script>
<style type="text/css">
body
{
font-family: Arial;
}

#name
{
background:#6BAA64;
color: #FFFFFF;
border:2px none;
padding:5px;
-webkit-border-radius:8px 8px;
-moz-border-radius:8px 8px;
border-radius:8px 8px;
text-align: center;
}
</style>
</head>

<body style="text-align: center;">
Name:
<br />
<input id="name" type="text" value="Your Name" />
</body>
</html>

我只是想设置一个简单的联系人/注册表单模型,所以当名称字段留空或未更改时,会变成红色(模糊)。

最佳答案

您在该代码中有许多错误:

$("#name").blur(function() {
if (!this.value) {
$(this).css('background-color', '#D23E42');
}
});​

错误:

  • 函数 => 函数
  • value => this.value
  • 输入的值永远不能是null,它只能是一个空字符串。
  • animate => css,原因是如果没有插件,您无法为背景颜色变化设置动画。
  • 颜色需要是字符串#D23E42 => '#D23E42'
  • background => background-color.
  • $("#name") => $(this)

停止在 w3school 学习可能是个好主意,因为它似乎没有返回......

关于javascript - 为什么 jQuery 背景动画不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10345842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com