[英]What is wrong with my javascript onclick and onmouseover?
我想做一个简单的测验。 我有这段代码,但是Javascript部分不起作用。 CSS可以,但是当涉及onclick
和onmouseover
什么也没有发生。 这是我的代码:
<html>
<head>
<style>
body {
background: url(bild.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
}
.a {
position: absolute;
top: 50%;
left: 50%;
margin-top: -130px;
margin-left: -500px;
width: 400px;
height: 50px;
font-size: 30;
color: black;
}
.b {
position: absolute;
top: 50%;
left: 50%;
margin-top: -130px;
margin-left: -20px;
width: 400px;
height: 50px;
font-size: 30;
color: black;
}
.c {
position: absolute;
top: 50%;
left: 50%;
margin-top: -30px;
margin-left: -500px;
width: 400px;
height: 50px;
font-size: 30;
color: black;
}
.d {
position: absolute;
top: 50%;
left: 50%;
margin-top: -30px;
margin-left: -20px;
width: 400px;
height: 50px;
font-size: 30;
color: black;
}
</style>
<title>Moseso.de Quiz</title>
</head>
<body>
<script>
function overa() {
document.getElementById("a").style.background="green";
}
function overb() {
document.getElementById("b").style.background="green";
}
function overc() {
document.getElementById("c").style.background="green";
}
function overd() {
document.getElementById("d").style.background="green";
}
function outa() {
document.getElementById("a").style.background="white";
}
function outb() {
document.getElementById("b").style.background="white";
}
function outc() {
document.getElementById("c").style.background="white";
}
function outd() {
document.getElementById("d").style.background="white";
}
function true() {
alert("Richtig!");
}
function false() {
alert("Falsch");
}
</script>
<button class="a" id="a" onmouseover="overa();" onmouseout="outa();" onclick"true();">Antwort A</>
<button class="b" id="b" onmouseover="overb();" onmouseout="outb();" onclick"false();">Antwort B</>
<button class="c" id="c" onmouseover="overc();" onmouseout="outc();" onclick"false();">Antwort C</>
<button class="d" id="d" onmouseover="overd();" onmouseout="outd();" onclick"false();">Antwort D</>
<script>
window.onload = function() {
document.getElementById("a").style.background="#E6E6E6";
document.getElementById("b").style.background="#E6E6E6";
document.getElementById("c").style.background="#E6E6E6";
document.getElementById("d").style.background="#E6E6E6";
}
</script>
</body>
</html>
如果有人因为我尝试了很多次而回答我的问题,那将是非常好的。 脚本是德语BTW :)
函数名称不能使用true或false之类的关键字。 要解决此错误,请将真或假方法名称更改为其他名称。
每个按钮都缺少适当的</button>
结束标记。 将</>
替换为</>
</button>
此外,您缺少onclick属性的赋值运算符。 确保在onclick之后和字符串分配之前出现=。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.