使用 jquery 在类中找到单击事件时,我有点困惑。 我的问题是如何识别我点击的 touchspin 向下还是向上 我正在使用 Bootstrap 触摸旋转。
<button type="button" class="btn btn-default bootstrap-touchspin-down">-</button>
<input type="number" value="18" onchange="calculatetotal(3)" style="width: 100%; padding: 0px; display: block;" class="ex_limit form-control" readonly="" id="qty3">
<button type="button" class="btn btn-default bootstrap-touchspin-up">+</button>
我想计算单击向上按钮时的某些过程和单击向下按钮时的某些过程。
在这里,我尝试使用类来识别按钮。
$('.btn, .btn-default, .bootstrap-touchspin-down').click(function(){
alert("down!");
});
请帮我完成这个任务。
最佳答案
$('[class*="bootstrap-touchspin-"]').click(function(event) {
var $this = $(this);
if ($this.hasClass('bootstrap-touchspin-down')) {
alert('down');
} else if ($this.hasClass('bootstrap-touchspin-up')) {
alert('up');
}
});
或者:
$('.bootstrap-touchspin-down').click(function(event) {
alert('down');
});
$('.bootstrap-touchspin-up').click(function(event) {
alert('up');
});
关于javascript - 识别 bootstrap touch spin 中的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359564/