【发布时间】:2018-03-08 15:51:38
【问题描述】:
我试图拥有多个按钮,每个按钮都有一个单独的调用功能,但要么所有按钮都做同样的事情,要么根本不工作。 所以这是我的第一个按钮:
<button id="study" onclick="call();">Study</button>
这是它的脚本:
var callCount = 0;
function one() {
changeImage1('Call one');
{
var img = document.getElementById("image");
img.src="images/tumblr_dash.gif";
document.getElementById("action").innerHTML = "You have decided to study";
}
}
function two() {
changeImage2('Call two');
{
var img = document.getElementById("image");
img.src="images/tumblr_dash.gif";
document.getElementById("action").innerHTML = "You have decided to start studying in a minute";
}
}
function three() {
changeImage3('Call three');
{
var img = document.getElementById("image");
img.src="images/study.gif";
document.getElementById("action").innerHTML = "You are currently studying";
}
}
function call(){
callCount++;
var btn = document.getElementById('study');
if(callCount == 1) one();
else if(callCount == 2) two();
else if(callCount == 3) three();
else btn.disabled = true;
//callOne = false /*!callOne;*/
}
而且效果很好。但是当我按下第二个按钮时:
<button id="eat" onclick="call1();">Eat</button>
哪个有这个脚本:
var callCount1 = 0;
function one1() {
changeImage1('Call one');
{
var img = document.getElementById("image");
img.src="images/tumblr_dash.gif";
document.getElementById("action").innerHTML = "You have decided to study";
}
}
function two1() {
changeImage2('Call two');
{
var img = document.getElementById("image");
img.src="images/tumblr_dash.gif";
document.getElementById("action").innerHTML = "You have decided to start eating in a minute";
}
}
function three1() {
changeImage3('Call three');
{
var img = document.getElementById("image");
img.src="images/eat.gif";
document.getElementById("action").innerHTML = "You are currently eating";
}
}
function call1(){
callCount1++;
var btn = document.getElementById('eat');
if(callCount1 == 1) one();
else if(callCount1 == 2) two();
else if(callCount1 == 3) three();
else btn.disabled = true;
//callOne = false /*!callOne;*/
}
它执行与第一个按钮相同的功能,而不是按照我的要求执行。我已尝试更改 ChangeImage 函数的数字,但它什么也没做我该如何解决这个问题?
【问题讨论】:
标签: javascript html button call