I have 2 buttons with values. For example, the value of the first button is 10, the value of the second button is 100. I also have an independent button A, and I need to get the number of times this button is clicked. That is, when I choose one of the 2 buttons with values, for example, when I select the button with the value of 10 and how many times I click on the A button, I want these values to multiply, how can I?
I can get the value of the button as below
<div id="container">
<button class="buttonbetbox" id="10" onclick="reply_click(this.id)"></button>
</div>
function reply_click(id)
{}
In this way, I can get how many times the button was clicked.
<button class="buttoncrab" id="btncrab" onclick="myFunction()">
</button>
function myFunction() {
count++;
}
As I explained above, I need to get the product of the selected button value and the number of times the other button was clicked.
You can save the number of times a button is clicked and the last selected value in variables in the global scope, and then do your multiplication:
var numberOfClicks = 0;
var currentlySelected = 10;
function reply_click(nb) {
if (nb == 10) {
currentlySelected = 10;
} else {
currentlySelected = 100;
}
numberOfClicks = 0;
}
function multiplyCount() {
numberOfClicks++;
console.log(numberOfClicks*currentlySelected);
}
See https://jsfiddle.net/81z62jxb/ for example on display in HTML
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.