gpt4 book ai didi

javascript - 如何使用 Javascript/jQuery 更改背景图片?

转载 作者:行者123 更新时间:2023-11-28 06:53:33 24 4
gpt4 key购买 nike

我目前正在研究如何在用户从聊天室的下拉菜单中选择特定组时更改我的 html 文档的背景图像。但我目前卡住了,我似乎无法让我的 jQuery 工作,如果你能提供任何帮助,我将非常感谢 :)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Soc Talk</title>

<script src="resource/js/jquery-1.10.2.min.js"></script>


<link rel="stylesheet" href="resource/css/bootstrap.min.css" />
<link rel="stylesheet" href="resource/css/style.css" />

<script>
$(".chatroom").click(function(){
$('.active').toggleClass('active');
$('.chatroom').toggleClass('active');

$('.jumbotron').fadeOut(500);
//change background image
$('.jumbotron').fadeIn(500);
$('.jumbotron').css('bg.png','url(resource/GamingSoc.jpg)');
});
</script>
</head>


<body>
<div class="jumbotron">
<div class="container">
<h1>SocTalk</h1>

</div>
</div>

<div class="container chat-signin">
<form class="form-signin">
<h2>Chat Login</h2>
<label for="nickname">Nickname</label> <input type="text" placeholder="Nickname" id="nickname">
<div>
<label for="chatroom" class="chatroom">Chatroom</label> <select size="1" id="chatroom">
<option>Select Room</option>
<option>Gaming Soc</option>
<option>Pokemon Soc</option>
</select>
</div>
<button type="submit" id="enterRoom">Sign in</button>
</form>
</div>
<!-- /container -->

<div class="container chat-wrapper">
<form id="do-chat">
<h2></h2>
<h4></h4>
<table id="response" ></table>
<fieldset>
<legend>Enter your message..</legend>
<div>
<input type="text" placeholder="Your message..." id="message" style="height:60px"/>
<input type="submit" value="Send message" />
<button type="button" id="Exit-room">Exit Room</button>
</div>
</fieldset>
</form>
</div>

<div class="alt1">
<div class="container">

</div>
</div>
<div class="alt2">
<div class="container">
<footer>
<p>Passive Aggressive Liberals</p>
</footer>
</div>
</div>
</body>
</html>

最佳答案

使用background-image属性改变或设置背景图片。

<script>
$(".chatroom").click(function(){
$('.active').toggleClass('active');
$('.chatroom').toggleClass('active');

$('.jumbotron').fadeOut(500);
//change background image
$('.jumbotron').fadeIn(500);
$('.jumbotron').css('background-image','url(resource/GamingSoc.jpg)');
});

Setting background-image using jQuery CSS property 可能重复

关于javascript - 如何使用 Javascript/jQuery 更改背景图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649874/

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