javascript - 识别 bootstrap touch spin 中的点击事件

标签 javascript jquery twitter-bootstrap

使用 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/

相关文章:

javascript - 拖放不起作用?

javascript - 如何使用querySelectorAll

javascript - 如何在向 dom 元素添加类后强制 ie8 重新绘制

jquery - 使用 jQuery 更改事件

javascript - 如何将插入符号设置为 contentEditable 元素中新添加的元素?

javascript - 如何一个接一个地放置一个盒子?

javascript - 生成的 SVG 图像不显示

JavaScript 函数在 Opera 中运行良好,但在 Firefox 中根本不起作用。为什么?

css - 为什么我的背景覆盖了我的主要部分?

html - 使 bootstrap 中的表格扩展到页面的全高