gpt4 book ai didi

javascript - 图像中的 onclick 永远不会被执行

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

我有一个图像,其中有两个以下代码,问题是当单击它时没有任何反应。

<div style="float: left;"><input onload="setValue()" type="image" src="img/board new/blank.png" name="saveForm" class="btTxt submit" id="spinner" onclick="spin()" />  </div>

这是我的完整代码。

<html>

<style>

body {
background-image: url(img/background4.png);
background-size: 100% 100%;
background-repeat: no-repeat;
}


</style>

<script>

var stop = false;
var spinResult;
var gameOver = false;
var oldHTML;
var newHTML;

function setValue() {

var rollResult = location.search.substr(location.search.indexOf("=")+1);
document.getElementById('own').innerHTML = "You own " + rollResult + " piece(s) on the board.";

}

function advanceSpinner(i) {
i = i || 1;

if (stop == false) {
if (i > 10)
i = 1; // change this to return if you don't want to run forever
document.getElementById("spinner").src = "img/board new/" + i + ".png";
spinResult = i;
setTimeout(function () { advanceSpinner(i + 1) }, 50);
}
}



function spin() {

var start = Math.floor(Math.random() * (10 - 1 + 1)) + 1
advanceSpinner(start);
setTimeout(function () {stop = true;}, 4000);
setTimeout(function () {checkWin();}, 4050);

}

function checkWin() {
/*
if (rollResult == 1 && spinResult == 1) {
alert("Win");
} else if (rollResult == 2 && spinResult == 1) {
alert("Win");
} else if (rollResult == 2 && spinResult == 3) {
alert("Win");
} else if (rollResult == 3 && spinResult == 1) {
alert("Win");
} else if (rollResult == 3 && spinResult == 3) {
alert("Win");
} else if (rollResult == 3 && spinResult == 6) {
alert("Win");
} else if (rollResult == 4 && spinResult == 1) {
alert("Win");
} else if (rollResult == 4 && spinResult == 3) {
alert("Win");
} else if (rollResult == 4 && spinResult == 6) {
alert("Win");
} else if (rollResult == 4 && spinResult == 8) {
alert("Win");
}
*/

var fadeEffect=function(){
return{
init:function(id, flag, target){
this.elem = document.getElementById(id);
clearInterval(this.elem.si);
this.target = target ? target : flag ? 100 : 0;
this.flag = flag || -1;
this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
this.elem.si = setInterval(function(){fadeEffect.tween()}, 20);
},
tween:function(){
if(this.alpha == this.target){
clearInterval(this.elem.si);
}else{
var value = Math.round(this.alpha + ((this.target - this.alpha) * .05)) + (1 * this.flag);
this.elem.style.opacity = value / 100;
this.elem.style.filter = 'alpha(opacity=' + value + ')';
this.alpha = value
}
}
}
}();


</script>

<head>
<title>Power Up! - Spin</title>
</head>

<body>

<div style="float: left;"><input onload="setValue()" type="image" src="img/board new/blank.png" name="saveForm" class="btTxt submit" id="spinner" onclick="spin()" /> </div>

</br>
<h2 id="own"> </h1>

<h1 id='result'> </h1>

</body>


</html>

最佳答案

我使用 JSFiddle 查看了您的源代码,我纠正了许多诸如“;”之类的内容声明结束:

http://jsfiddle.net/uz3gk/

JS

function setValue() {
rollResult = location.search.substr(location.search.indexOf("=") + 1);
}



var stop = false;
var spinResult;
var gameOver = false;
var oldHTML;
var newHTML;
var rollResult;
var start;

function setValue() {

rollResult = location.search.substr(location.search.indexOf("=") + 1);
//document.getElementById('own').innerHTML = "You own " + rollResult + " piece(s) on the board.";

}


function advanceSpinner(i) {
console.log(i);
i = i || 1;

console.log(stop);
if (stop === false) {
if (i < 10) {
// i = 1;
document.getElementById("spinner").src = "img/board new/" + i + ".png";
spinResult = i;
setTimeout(function () {
advanceSpinner(i + 1);
}, 50);
}
}
}


function spin() {
alert("Test if being executed.");
start = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
advanceSpinner(start);
setTimeout(function () {
stop = true;
}, 4000);
setTimeout(function () {
checkWin();
}, 4050);
}

function checkWin() {
/*
if (rollResult == 1 && spinResult == 1) {
alert("Win");
} else if (rollResult == 2 && spinResult == 1) {
alert("Win");
} else if (rollResult == 2 && spinResult == 3) {
alert("Win");
} else if (rollResult == 3 && spinResult == 1) {
alert("Win");
} else if (rollResult == 3 && spinResult == 3) {
alert("Win");
} else if (rollResult == 3 && spinResult == 6) {
alert("Win");
} else if (rollResult == 4 && spinResult == 1) {
alert("Win");
} else if (rollResult == 4 && spinResult == 3) {
alert("Win");
} else if (rollResult == 4 && spinResult == 6) {
alert("Win");
} else if (rollResult == 4 && spinResult == 8) {
alert("Win");
}
*/
}

var fadeEffect = function () {
return {
init: function (id, flag, target) {
this.elem = document.getElementById(id);
clearInterval(this.elem.si);
this.target = target ? target : flag ? 100 : 0;
this.flag = flag || -1;
this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
this.elem.si = setInterval(function () {
fadeEffect.tween();
}, 20);
},
tween: function () {
if (this.alpha == this.target) {
clearInterval(this.elem.si);
} else {
var value = Math.round(this.alpha + ((this.target - this.alpha) * 0.05)) + (1 * this.flag);
this.elem.style.opacity = value / 100;
this.elem.style.filter = 'alpha(opacity=' + value + ')';
this.alpha = value;
}
}
};
}();

这是您要找的吗?

编辑:

我更正了 JSFiddle,您现在可以检查一下是否可以吗?

关于javascript - 图像中的 onclick 永远不会被执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20926586/

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