拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 HTML中的影像标签不使用jQuery点击

HTML中的影像标签不使用jQuery点击

白鹭 - 2022-02-23 2086 0 0

我正在制作一个答题器游戏,但是当我单击它时,我的其中一个影像(用于升级)将不起作用。问题出在辅助 div 影像中。我正在为 js 使用 HTML、css、javascript 和 jQuery

代码:

var clicks = 0;
var perclick = 1;
var persec = 0;
var costup1 = 12;
var currentup1 = 0;
var costup2 = 27;
var currentup2 = 0;
setInterval(sec, 1000)
//click and upgrade
$(document).ready(function() {
  $("#sun").click(function() {
    add()
  })
  $("#up1").click(function() {
    if (clicks >= costup1) {
      clicks = clicks - costup1
      currentup1 = currentup1   1;
      costup1 = ((currentup1   1) * 12);
      perclick = perclick   1
      update()
    } else {
      alert("You Don't Have Enough Clicks");
    }
  })
  $("#up2").click(function() {
    if (click >= currentup2) {
      clicks = clicks - costup2
      currentup2 = currentup2   1;
      costup2 = ((currentup2   1) * 27)
      persec = persec   1;
      update()
    } else {
      alert("You Don't Have Enough Clicks")
    }
  })
  //Save and load
  $(document).ready(function() {
    $("#save").click(function() {
      localStorage.setItem("clicks", clicks)
      localStorage.setItem("perclick", perclick)
      localStorage.setItem("persec", persec)
      localStorage.setItem("currentup1", currentup1)
    })
    $("#load").click(function() {
      clicks = localStorage.getItem("clicks")
      clicks = parseInt(clicks)
      perclick = localStorage.getItem("perclick")
      perclick = parseInt(perclick)
      persec = localStorage.getItem("persec")
      persec = parseInt(persec)
      currentup1 = localStorage.getItem("currentup1")
      currentup1 = parseInt(currentup1)

    })
  })
})


function add() {
  clicks = clicks   perclick;
  update()
}

function sec() {
  clicks = clicks   persec;
  update()
}

function update() {

  document.getElementById("costmag").innerHTML = ((currentup1   1) * 12)   " Clicks";
  document.getElementById("curmag").innerHTML = "You Own "   currentup1   " Magnifying Glasses( 1 Clicks Per Click)"
  document.getElementById("scoreText").innerHTML = clicks   " Clicks";
  document.getElementById("clickText").innerHTML = "You Are Gaining "   perclick   " Clicks Per Click"
  document.getElementById("secText").innerHTML = "You Are Gaining "   persec   " Clicks Per Second"

  document.getElementById("helpcur").innerHTML = "You Have "   currentup2   " Helpers( 1 Clicks Per Second)"
  document.getElementById("helpcos").innerHTML = ((currentup2   1) * 27)   " Clicks";

}
img {
  -webkit-user-drag: none;
}

button {
  box-sizing: border-box;
  background-color: #000000;
  color: cyan;
  border: none;
  font-size: 16px;
}

body {
  font-family: Architects Daughter;
}

```
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Clicker Game Made With jQuery</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="script.js"></script>
  <link rel="stylesheet" href="styles.css">
</head>

<body>

  <p id="clickText"> You Are Gaining 1 Clicks Per Click </p>
  <p id="secText"> You Are Gaining 0 Clicks Per Second </p>
  <a href="javascript:;"><img src="Images/sun.png" id="sun"></a>
  <p id="scoreText">0 Clicks</p>


  <div class="magnify">
    <p id="curmag"> You Own 0 Magnifying Glasses( 1 Clicks Per Click)</p>
    <a href="javascript:;"><img src="Images/magnify-glass.png" width="50px" height="50px" id="up1"></a>
    <p id="costmag"> 12 Clicks </p>
  </div>



  <div class="helper">
    <p id="helpcur"> You Have 0 Helpers ( 1 Clicks Per Second)</p>
    <a href="javascript:;"><img src="Images/helper.png" width="60px" height="80px" id="up2"></a>
    <p id="helpcos"> 27 Clicks </p>
  </div>

  <div class="svld">
    <button id="save">Save</button>
    <button id="load">Load</button>
  </div>

</body>

</html>

uj5u.com热心网友回复:

在帮助影像点击事件的 if 条件中使用clicks变量。

var clicks = 0;
var perclick = 1;
var persec = 0;
var costup1 = 12;
var currentup1 = 0;
var costup2 = 27;
var currentup2 = 0;
setInterval(sec, 1000)
//click and upgrade
$(document).ready(function() {
  $("#sun").click(function() {
    add()
  })
  $("#up1").click(function() {
    if (clicks >= costup1) {
      clicks = clicks - costup1
      currentup1 = currentup1   1;
      costup1 = ((currentup1   1) * 12);
      perclick = perclick   1
      update()
    } else {
      alert("You Don't Have Enough Clicks");
    }
  })
  $("#up2").click(function() {
    if (clicks >= currentup2) {
      clicks = clicks - costup2
      currentup2 = currentup2   1;
      costup2 = ((currentup2   1) * 27)
      persec = persec   1;
      update()
    } else {
      alert("You Don't Have Enough Clicks")
    }
  })
  //Save and load
  $(document).ready(function() {
    $("#save").click(function() {
      localStorage.setItem("clicks", clicks)
      localStorage.setItem("perclick", perclick)
      localStorage.setItem("persec", persec)
      localStorage.setItem("currentup1", currentup1)
    })
    $("#load").click(function() {
      clicks = localStorage.getItem("clicks")
      clicks = parseInt(clicks)
      perclick = localStorage.getItem("perclick")
      perclick = parseInt(perclick)
      persec = localStorage.getItem("persec")
      persec = parseInt(persec)
      currentup1 = localStorage.getItem("currentup1")
      currentup1 = parseInt(currentup1)

    })
  })
})


function add() {
  clicks = clicks   perclick;
  update()
}

function sec() {
  clicks = clicks   persec;
  update()
}

function update() {

  document.getElementById("costmag").innerHTML = ((currentup1   1) * 12)   " Clicks";
  document.getElementById("curmag").innerHTML = "You Own "   currentup1   " Magnifying Glasses( 1 Clicks Per Click)"
  document.getElementById("scoreText").innerHTML = clicks   " Clicks";
  document.getElementById("clickText").innerHTML = "You Are Gaining "   perclick   " Clicks Per Click"
  document.getElementById("secText").innerHTML = "You Are Gaining "   persec   " Clicks Per Second"

  document.getElementById("helpcur").innerHTML = "You Have "   currentup2   " Helpers( 1 Clicks Per Second)"
  document.getElementById("helpcos").innerHTML = ((currentup2   1) * 27)   " Clicks";

}
img {
  -webkit-user-drag: none;
}

button {
  box-sizing: border-box;
  background-color: #000000;
  color: cyan;
  border: none;
  font-size: 16px;
}

body {
  font-family: Architects Daughter;
}

```
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Clicker Game Made With jQuery</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="script.js"></script>
  <link rel="stylesheet" href="styles.css">
</head>

<body>

  <p id="clickText"> You Are Gaining 1 Clicks Per Click </p>
  <p id="secText"> You Are Gaining 0 Clicks Per Second </p>
  <a href="javascript:;"><img src="Images/sun.png" id="sun"></a>
  <p id="scoreText">0 Clicks</p>


  <div class="magnify">
    <p id="curmag"> You Own 0 Magnifying Glasses( 1 Clicks Per Click)</p>
    <a href="javascript:;"><img src="Images/magnify-glass.png" width="50px" height="50px" id="up1"></a>
    <p id="costmag"> 12 Clicks </p>
  </div>



  <div class="helper">
    <p id="helpcur"> You Have 0 Helpers ( 1 Clicks Per Second)</p>
    <a href="javascript:;"><img src="Images/helper.png" width="60px" height="80px" id="up2"></a>
    <p id="helpcos"> 27 Clicks </p>
  </div>

  <div class="svld">
    <button id="save">Save</button>
    <button id="load">Load</button>
  </div>

</body>

</html>

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *