[英]Multiply the number of clicks of the selected button and the other button
I have 2 buttons with values.我有 2 个带值的按钮。 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.
比如第一个按钮的值为10,第二个按钮的值为100。我还有一个独立的按钮A,我需要得到这个按钮被点击的次数。 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?
也就是说,当我选择2个有值的按钮之一时,例如,当我select这个按钮的值为10时,我点击A按钮多少次,我希望这些值相乘,我该怎么做?
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:您可以在全局 scope 的变量中保存单击按钮的次数和最后选择的值,然后进行乘法运算:
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参见https://jsfiddle.net/81z62jxb/例如在 HTML 中显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.