这个函数有什么问题?我无法让按钮出现,也无法让函数运行
What is wrong with this function? I can't get the button to appear and the function to run
<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'"
做什么。它看起来像你试图使用对象语法没有设置到一个变量?或者使用适当的符号…
不应该在那里:
"getElementbyId:'links'"}
您的<form>
未正确关闭;
getElementbyId应该以id作为参数
看起来你想改变页面背景
document.body.style.backgroundImage = "url('colombia.jpg')";
演示:http://jsfiddle.net/jzmsb/
如果你想改变其他东西的背景,它需要一个id
<div id="changeme"></div>
然后用
作为目标document.getElementById("changeme");
为
document.getElementById("changeme").style.backgroundImage = "url('colombia.jpg')";
http://jsfiddle.net/jzmsb/1/相关文章:
- 关注函数运行过的表单字段(新手)
- 在函数运行时显示对话
- Javascript - 加载函数运行时未定义的变量
- Javascript变量在函数运行后不断重置自身
- 如何让 setTimeout 函数运行,然后停止使用循环
- 如何在函数运行之前隐藏 CSS
- 使用 .on 函数运行 jQuery 声明函数
- 在函数运行期间关闭 onClick
- jQuery停止函数运行两次
- Javascript:如何在函数运行完成之前对文档进行更改
- nodejs - 为什么我的异步函数运行两次
- 在传递值后停止函数运行
- 如何在 javascript 中的函数中将字符串作为函数运行
- 如何停止计时器函数运行
- 在浏览器空闲后保持设置超时函数运行
- JQuery:阻止一个函数运行,直到满足另一个函数条件“X”时间
- Angular 提供程序服务需要 init 函数运行一次
- 更新 Angular $interval 中的变量会导致其他函数运行
- 如何阻止此 setTimeout 函数运行
- 传入函数数组作为参数,对于函数中的每个函数运行函数