gpt4 book ai didi

javascript - 我如何通过 jquery 更改背景颜色?

转载 作者:太空宇宙 更新时间:2023-11-04 14:16:37 25 4
gpt4 key购买 nike

我需要你的帮助:

我有一个网站,我想在将鼠标悬停在菜单上时更改 bg-coler(就像在 rhcp-website 上一样),我已经用 jquery 尝试过,但它没有用..

(明确一点,我不想更改包含我的菜单的 div 容器的背景颜色,它应该是整个主体..--> 代码)

谢谢!

代码:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>

<script type="text/javascript">
$('.start').hover(function () {
$('html').css('background-color', '#676767')
});
</script>

<?php include_once 'template.php' ?>

<title>Maximilian Braun</title>
</head>

<body>
<div class="start">
<h1>
<a href="actor.php" >Schauspieler</a> - <a href="foto.php">Fotograf</a>
</h1>
</div>
<?php echo footer();?>
</body>

最佳答案

尝试将您的代码包装在 document's ready 处理程序中,

$(function(){
$('.start').hover(function(){$('html').css('background-color','#676767') } );
});

由于 Jquery 无法识别具有类 start 的元素,而相关元素尚未加载。

关于javascript - 我如何通过 jquery 更改背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24674381/

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