按钮不响应 Ionic 中的点击

Buttons are not responding to clicks in Ionic

我将以下按钮绝对定位在 canvas 元素上:

<button class="left">Left</button>

这是应该响应按钮点击的 JavaScript:

$(".left").mousedown(function() {
   leftTimer = setTimeout(moveLeft, 10);
}).mouseup(function() {
   clearTimeout(leftTimer);
});

var leftTimer,
moveLeft = function() {
  if (circleX > 0) {
    circleX -= 4;
  }
  $("h1.title").text('Clicked Left');
  leftTimer = setTimeout(moveLeft, 10);
};

我添加了标题行以检查是否有延迟。当我正常点击按钮时,没有任何反应,标题没有改变。我必须按住按钮一段时间才能将文本更改为 "Clicked Left" 或移动我的目标元素。即便如此,我第一次触摸按钮的时间和文本更改的时间之间也有相当大的延迟。这是为什么 ?如果我需要提供更多信息,请告诉我。

您的 Ionic 应用实际上应该有 Angular,并在您要处理的 div 上使用 ng-click 元素。

根据文档,Angular需要 JS:

Ionic currently requires AngularJS in order to work at its full potential. While you can still use the CSS portion of the framework, you'll miss out on powerful UI interactions, gestures, animations, and other things.

这是一个 JSBin,使您成为 HTML 和 AngularJS 之间的基本绑定:https://jsbin.com/rifigakube/edit?html,js,output

如果您是这项技术的新手,这里有一份 AngularJS 入门列表(如果您了解 Javascript,学习起来会很容易):

最后,当您认为自己对 AngularJS 有足够的信心时:https://scotch.io/tutorials/create-your-first-mobile-app-with-angularjs-and-ionic

(我真的建议你在做最后一个之前学习AngularJS,否则你会卡住)

希望对您有所帮助。