gpt4 book ai didi

javascript - 这个函数有什么问题吗?我无法显示按钮并运行函数

转载 作者:行者123 更新时间:2023-12-02 17:15:11 25 4
gpt4 key购买 nike

    <script>
function changeBgImage(){
document.body.getElementbyId.style.backgroundImage = "url('colombia.jpg')"; "getElementbyId:'links'"}
</script>
</head>

<body>

<img src="worldcup.jpg" id="worldcup" height="200" width="600">
<img src="logo.jpg" id="logo1" height="200" width="200">
<img src="logo.jpg" id="logo2" height="200" width="200">

<p id="teams"> <big> <big> Teams that are in the World Cup </big></big>
<br> <big> Group A: </big>
<br> Brazil, Mexico, Croatia, Cameroon <br>
<big> Group B: </big>
<br> Netherlands, Chile, Spain, Australia <br>
<big> Group C: </big>
<br> Colombia, Ivory Coast, Japan, Greece <Br>
<big> Group D: </big>
<br> Costa Rica, Uruguay, Italy, England <br>
<big> Group E: </big> <br>
France, Ecuador, Switzerland, Honduras <Br>
<big> Group F: </big> <br>
Argentina, Nigeria, Iran, Bosnia
<br>
<big> Group G: </big> <br>
Germany, United States, Ghana, Portugal <br>
<big> Group H: </big> <br>
Belgium, Algeria, Russia, Korea Republic
</p>

<p id="favorites">
<big> <big> <big> <big> My Favorites </big> </big> </big> <br>
In this section of my webpage I would like to talk about my Favorite teams,
obviously I am rooting 100% for Colombia because it is my country, as well as Costa Rica.
Another obvious team I always root for is the US, because well...I'm also American. This World Cup has been
so great, I am extremely proud of all of the Latin American teams that have qualified for the next round and I
hope that a Latin American team makes it to the final. I am very excited because I will be in Miami for the final and I
am sure it will be very exciting.
</p>
<img src="colombia.jpg" id="colombia" height="400px" width="400px">

<p id="soccerlove"> <big> <big> <big> Why I LOVE soccer! </big></big>
<br>
There are many many reasons why I love soccer. First of all, I was raised watching soccer games
and cheering on my family's favorite teams. It becomes a tradition,and when you are away from your family, you can watch a soccer game and feel at home.
Soccer is such a beautiful sport, on the two videos on either side of this section you will find 2 reasons why I think soccer is so beautiful. On the left, a compilation
of amazing goals, and on the right, the way that Colombian celebrate their goals! </p>

<p id="goal1">
<iframe width="350" height="315" src="http://www.youtube.com/embed/RGEm9T4Smts" frameborder="0" allowfullscreen></iframe> </p>
<p id="goal2">

<iframe width="350" height="315" src="http://www.youtube.com/embed/FEJzRdU1viE" frameborder="0" allowfullscreen></iframe> </p>

<p id="links">
<h1> Who do you think will win? </h1>
<form>
<input type="button" name="links" id="links"
value="Who will be the winner?!"
onclick="changeBgImage">
</p>
<form>

所以我需要运行“changeBgImage”函数...我怎样才能让它工作我希望它成为页面底部的一个按钮。我已经尝试了各种方法,但仍然无法使其工作,请问有人可以帮助我吗?

最佳答案

document.body.getElementbyId.style.backgroundImage = "url('colombia.jpg')";

getElementById 是一个函数,它需要一个参数。

getElementById("idofyourelementhere");

顺便说一下,我不知道你在用 "getElementbyId:'links'" 做什么。看起来您正在尝试使用对象语法而不设置变量?或者使用正确的符号..

关于javascript - 这个函数有什么问题吗?我无法显示按钮并运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24494670/

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