English 中文(简体)
B. 如何寻找纽芬兰语
原标题:how to find what button is pressed

i am making a clicker game and need to find out which button is being clicked. i am not sure how to do this.

这是我的 j。

var multiplyer = 1
var carparts = 0;
document.getElementById("karpartz").innerHTML = carparts;
function onButtonClick() {
    carparts = carparts + multiplyer;
    document.getElementById("karpartz").innerHTML = carparts; 
}

const button = document.querySelector( button ); 
  button.addEventListener( click , onButtonClick); 

这是我的html。

<button type="submit">
  <img src= "example"
alt="buttonpng" border="0" />
</button>

<button>
  upgrade click power
</button>
<button>
  upgrade idle scrapping
</button>

<p id="karpartz"></p>

<html>

  <body>
    <h1>
      <script type="text/javascript">
        document.write(karpartz)

      </script>
    </h1>
  </body>

</html>

如何找到被点击的人

i 还无法找到摆脱[目标超文本字部分]的方法

问题回答

在每一纽伦加插活动手,然后通过某种识别符号。 现有目标(使用你顿文)。 下面是代号:

const onButtonClick = (buttonText) => 
  console.log(`you clicked the ${buttonText ||  submit } button`);


const buttons = document.querySelectorAll( button ); // Select all buttons

buttons.forEach(button => button.addEventListener(
   click , event => onButtonClick(
    event.currentTarget.textContent.trim())));
<button type="submit">
  <img src= "example"
alt="buttonpng" border="0" />
</button>

<button>
  upgrade click power
</button>
<button>
  upgrade idle scrapping
</button>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签